Refine search
@Override public boolean isEmpty(String database, String table) throws SQLException { String sql = String.format(SELECT_SQL_FORMAT, database, table); try (PreparedStatement pstmt = this.conn.prepareStatement(sql); ResultSet resultSet = pstmt.executeQuery();) { if (!resultSet.first()) { throw new RuntimeException("Should have received at least one row from SQL " + pstmt); } return 0 == resultSet.getInt(1); } }
@Override public boolean isEmpty(String database, String table) throws SQLException { String sql = String.format(SELECT_SQL_FORMAT, database, table); try (PreparedStatement pstmt = this.conn.prepareStatement(sql); ResultSet resultSet = pstmt.executeQuery();) { if (!resultSet.first()) { throw new RuntimeException("Should have received at least one row from SQL " + pstmt); } return 0 == resultSet.getInt(1); } }
@Override public boolean isEmpty(String database, String table) throws SQLException { String sql = String.format(SELECT_SQL_FORMAT, database, table); try (PreparedStatement pstmt = this.conn.prepareStatement(sql); ResultSet resultSet = pstmt.executeQuery();) { if (!resultSet.first()) { throw new RuntimeException("Should have received at least one row from SQL " + pstmt); } return 0 == resultSet.getInt(1); } }
pstmt.setString(2, table); LOG.info("Retrieving column type information from SQL: " + pstmt); try (ResultSet rs = pstmt.executeQuery()) { if (!rs.first()) { throw new IllegalArgumentException("No result from information_schema.columns");
pstmt.setString(2, table); log.info("Retrieving column type information from SQL: " + pstmt); try (ResultSet rs = pstmt.executeQuery()) { if (!rs.first()) { throw new IllegalArgumentException("No result from information_schema.columns");
pstmt.setString(2, table); LOG.info("Retrieving column type information from SQL: " + pstmt); try (ResultSet rs = pstmt.executeQuery()) { if (!rs.first()) { throw new IllegalArgumentException("No result from information_schema.columns");
public static int getProductAllCount(DataSource ds, String key, String sql_allcount) throws Exception { Connection c = null; PreparedStatement ps = null; ResultSet rs = null; int ret = 0; try { c = ds.getConnection(); ps = c.prepareStatement(sql_allcount, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ps.setString(1, key); rs = ps.executeQuery(); if (rs.first()) { ret = rs.getInt(1); } } catch (SQLException se) { throw new Exception("SQLException: " + se.getMessage()); } finally { if (rs != null) rs.close(); if (ps != null) ps.close(); if (c != null) c.close(); } return ret; }
public static boolean releaseGlobalLock(String name) { try (Connection conn = getConnectionForGlobalLocks(name, false);) { if (conn == null) { s_logger.error("Unable to acquire DB connection for global lock system"); assert (false); return false; } try (PreparedStatement pstmt = conn.prepareStatement("SELECT COALESCE(RELEASE_LOCK(?), 0)");) { pstmt.setString(1, name); try (ResultSet rs = pstmt.executeQuery();) { if (rs != null && rs.first()) { return rs.getInt(1) > 0; } s_logger.error("releaseGlobalLock:RELEASE_LOCK() returns unexpected result"); } } } catch (SQLException e) { s_logger.error("RELEASE_LOCK() throws exception ", e); } catch (Throwable e) { s_logger.error("RELEASE_LOCK() throws exception ", e); } return false; }
@Override public int getProxyActiveLoad(long proxyVmId) { TransactionLegacy txn = TransactionLegacy.currentTxn(); PreparedStatement pstmt = null; try { pstmt = txn.prepareAutoCloseStatement(GET_PROXY_ACTIVE_LOAD); pstmt.setLong(1, proxyVmId); ResultSet rs = pstmt.executeQuery(); if (rs != null && rs.first()) { return rs.getInt(1); } } catch (SQLException e) { s_logger.debug("Caught SQLException: ", e); } return 0; }
@Override public int getProxyStaticLoad(long proxyVmId) { TransactionLegacy txn = TransactionLegacy.currentTxn(); ; PreparedStatement pstmt = null; try { pstmt = txn.prepareAutoCloseStatement(GET_PROXY_LOAD); pstmt.setLong(1, proxyVmId); ResultSet rs = pstmt.executeQuery(); if (rs != null && rs.first()) { return rs.getInt(1); } } catch (SQLException e) { s_logger.debug("Caught SQLException: ", e); } return 0; }
public static boolean getGlobalLock(String name, int timeoutSeconds) { Connection conn = getConnectionForGlobalLocks(name, true); if (conn == null) { s_logger.error("Unable to acquire DB connection for global lock system"); return false; } try (PreparedStatement pstmt = conn.prepareStatement("SELECT COALESCE(GET_LOCK(?, ?),0)");) { pstmt.setString(1, name); pstmt.setInt(2, timeoutSeconds); try (ResultSet rs = pstmt.executeQuery();) { if (rs != null && rs.first()) { if (rs.getInt(1) > 0) { return true; } else { if (s_logger.isDebugEnabled()) s_logger.debug("GET_LOCK() timed out on lock : " + name); } } } } catch (SQLException e) { s_logger.error("GET_LOCK() throws exception ", e); } catch (Throwable e) { s_logger.error("GET_LOCK() throws exception ", e); } removeConnectionForGlobalLocks(name); closeAutoCloseable(conn, "connection for global lock"); return false; }
rs = pstmt.executeQuery(); if (rs.first()) { networkOfferingId = rs.getLong(1); } else { rs = pstmt.executeQuery(); if (rs.first()) { f5HostId = rs.getLong(1); } else { pstmt.setLong(1, f5HostId); rs = pstmt.executeQuery(); if (rs.first()) { f5DeviceId = rs.getLong(1); } else { pstmt.setLong(1, zoneId); rs = pstmt.executeQuery(); if (rs.first()) { srxHostId = rs.getLong(1); } else { pstmt.setLong(1, srxHostId); rs = pstmt.executeQuery(); if (rs.first()) { srxDevivceId = rs.getLong(1); } else {
rs = pstmt.executeQuery(); if (rs.first()) { networkOfferingId = rs.getLong(1); } else { rs = pstmt.executeQuery(); if (rs.first()) { f5HostId = rs.getLong(1); } else { pstmt.setLong(1, f5HostId); rs = pstmt.executeQuery(); if (rs.first()) { f5DeviceId = rs.getLong(1); } else { pstmt.setLong(1, zoneId); rs = pstmt.executeQuery(); if (rs.first()) { srxHostId = rs.getLong(1); } else { pstmt.setLong(1, srxHostId); rs = pstmt.executeQuery(); if (rs.first()) { srxDevivceId = rs.getLong(1); } else {
try(ResultSet sel_id_off_rs = sel_id_off_pstmt.executeQuery();) { if (sel_id_off_rs.first()) { networkOfferingId = sel_id_off_rs.getLong(1); } else { try(ResultSet sel_id_host_pstmt_rs = sel_id_host_pstmt.executeQuery();) { if (sel_id_host_pstmt_rs.first()) { f5HostId = sel_id_host_pstmt_rs.getLong(1); } else { sel_id_ext_pstmt.setLong(1, f5HostId); try(ResultSet sel_id_ext_rs = sel_id_ext_pstmt.executeQuery();) { if (sel_id_ext_rs.first()) { f5DeviceId = sel_id_ext_rs.getLong(1); } else { sel_id_hostdc_pstmt.setLong(1, zoneId); try(ResultSet sel_id_hostdc_pstmt_rs = sel_id_hostdc_pstmt.executeQuery();) { if (sel_id_hostdc_pstmt_rs.first()) { srxHostId = sel_id_hostdc_pstmt_rs.getLong(1); } else { sel_id_ext_frwl_pstmt.setLong(1, srxHostId); try(ResultSet sel_id_ext_frwl_pstmt_rs = sel_id_ext_frwl_pstmt.executeQuery();) { if (sel_id_ext_frwl_pstmt_rs.first()) { srxDevivceId = sel_id_ext_frwl_pstmt_rs.getLong(1); } else {
conn.setAutoCommit(true); pstmt = conn.prepareStatement(String.format("select get_lock('%s', %s)", name, timeout)); ResultSet rs = pstmt.executeQuery(); if (rs == null) { String err = "Unable to get DB lock: " + name + ", internal database error happened"; throw new CloudRuntimeException(err); } else if (rs.first() && rs.getInt(1) == 0) { throw new CloudRuntimeException(String.format("lock[%s] failed, timeout after %s seconds", name, timeout));
try { pstmt = conn.prepareStatement(String.format("select release_lock('%s')", name)); ResultSet rs = pstmt.executeQuery(); if (rs == null) { throw new CloudRuntimeException("Mysql cannot find lock: " + name); } else if (rs.first() && rs.getInt(1) == 0) { String err = "Unable to release DB lock: " + name + ", lock: " + name + " is not held by this connection, internal error"; throw new CloudRuntimeException(err);
public boolean isLoginFree(String login) throws SQLException { PreparedStatement pst = con.prepareStatement("select login " + "from User " + "where login=?"); pst.setString(1, login); ResultSet rs = pst.executeQuery(); return !rs.first(); }
rs.first(); while( rs.next() ){ float hourlyRate = rs.getFloat("HourlyRate"); int employeeID = rs.getInt("employeeID "); //Do your code to calculate and update other database.... //You need to check for INSERT or UPDATE in the other database. //Make one select on the current tupel //e.g. PreparedStatement checkUpdateOrInsert = conOnOtherDb.prepareStatement("SELECT employeeID FROM otherSchema.otherTable"); ResultSet rsCheckUpdateOrInsert = checkUpdateOrInsert .executeQuery(); if( !rsCheckUpdateOrInsert.first() ){ //On onther DB you must insert }//untested, (bool) first should return false on no row? else{ //On onther DB you must update } }
@Override public boolean isEmpty(String database, String table) throws SQLException { String sql = String.format(SELECT_SQL_FORMAT, database, table); try (PreparedStatement pstmt = this.conn.prepareStatement(sql); ResultSet resultSet = pstmt.executeQuery();) { if (!resultSet.first()) { throw new RuntimeException("Should have received at least one row from SQL " + pstmt); } return 0 == resultSet.getInt(1); } }
@Override public boolean isEmpty(String database, String table) throws SQLException { String sql = String.format(SELECT_SQL_FORMAT, database, table); try (PreparedStatement pstmt = this.conn.prepareStatement(sql); ResultSet resultSet = pstmt.executeQuery();) { if (!resultSet.first()) { throw new RuntimeException("Should have received at least one row from SQL " + pstmt); } return 0 == resultSet.getInt(1); } }