List of usage examples for java.sql ResultSet close
void close() throws SQLException;
ResultSet
object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed. From source file:edu.ucsb.nceas.MCTestCase.java
protected static Vector<Hashtable<String, Object>> dbSelect(String sqlStatement, String methodName) throws SQLException { Vector<Hashtable<String, Object>> resultVector = new Vector<Hashtable<String, Object>>(); DBConnectionPool connPool = DBConnectionPool.getInstance(); DBConnection dbconn = DBConnectionPool.getDBConnection(methodName); int serialNumber = dbconn.getCheckOutSerialNumber(); PreparedStatement pstmt = null; debug("Selecting from db: " + sqlStatement); pstmt = dbconn.prepareStatement(sqlStatement); pstmt.execute();/* w w w . ja v a 2 s . c o m*/ ResultSet resultSet = pstmt.getResultSet(); ResultSetMetaData rsMetaData = resultSet.getMetaData(); int numColumns = rsMetaData.getColumnCount(); debug("Number of data columns: " + numColumns); while (resultSet.next()) { Hashtable<String, Object> hashTable = new Hashtable<String, Object>(); for (int i = 1; i <= numColumns; i++) { if (resultSet.getObject(i) != null) { hashTable.put(rsMetaData.getColumnName(i), resultSet.getObject(i)); } } debug("adding data row to result vector"); resultVector.add(hashTable); } resultSet.close(); pstmt.close(); DBConnectionPool.returnDBConnection(dbconn, serialNumber); return resultVector; }
From source file:at.becast.youploader.account.Account.java
public int save() throws IOException { ObjectMapper mapper = new ObjectMapper(); LOG.info("Saving account"); try {/*from w ww .j av a 2s .c om*/ PreparedStatement stmt = c .prepareStatement("INSERT INTO `accounts` (`name`,`refresh_token`,`cookie`) VALUES(?,?,?)"); stmt.setString(1, this.name); stmt.setString(2, this.refreshToken); stmt.setString(3, mapper.writeValueAsString(this.cdata)); stmt.execute(); ResultSet rs = stmt.getGeneratedKeys(); stmt.close(); if (rs.next()) { int id = rs.getInt(1); rs.close(); LOG.info("Account saved"); return id; } else { LOG.error("Could not save account {}!", this.name); return -1; } } catch (SQLException e) { LOG.error("Could not save account Ex:", e); return -1; } }
From source file:de.blizzy.backup.database.Database.java
private void closeQuietly(ResultSet rs) { if (rs != null) { try {/* www. jav a 2 s .c o m*/ rs.close(); } catch (SQLException e) { // ignore } } }
From source file:ke.co.tawi.babblesms.server.persistence.contacts.PhoneDAO.java
/** * @see ke.co.tawi.babblesms.server.persistence.contacts.BabblePhoneDAO#getPhone(java.lang.String) *//*from w w w. jav a2 s . c o m*/ @Override public Phone getPhone(String uuid) { Phone phone = null; try (Connection conn = dbCredentials.getConnection(); PreparedStatement psmt = conn.prepareStatement("SELECT * FROM phone WHERE " + "uuid = ?;");) { psmt.setString(1, uuid); ResultSet rset = psmt.executeQuery(); if (rset.next()) { phone = beanProcessor.toBean(rset, Phone.class); } rset.close(); } catch (SQLException e) { logger.error("SQLException when getting phone with uuid: " + uuid); logger.error(ExceptionUtils.getStackTrace(e)); } return phone; }
From source file:com.mtgi.analytics.sql.BehaviorTrackingDataSourceTest.java
@Test public void testStaticSql() throws Exception { //test simple static insert / update. assertFalse(stmt.execute("insert into TEST_TRACKING values (1, 'hello', null)")); //test batching. each batch should create one event. stmt.addBatch("insert into TEST_TRACKING values (3, 'batch', '1')"); stmt.addBatch("insert into TEST_TRACKING values (4, 'batch', '2')"); stmt.executeBatch();/*from ww w .j av a 2 s .c o m*/ assertFalse(stmt.execute("insert into TEST_TRACKING values (2, 'goodbye', null)")); assertEquals(4, stmt.executeUpdate("update TEST_TRACKING set DESCRIPTION = 'world'")); //test query. ResultSet rs = stmt.executeQuery("select ID from TEST_TRACKING order by ID"); int index = 0; long[] keys = { 1L, 2L, 3L, 4L }; while (rs.next()) assertEquals(keys[index++], rs.getLong(1)); rs.close(); assertEquals(4, index); manager.flush(); assertEventDataMatches("BehaviorTrackingDataSourceTest.testStaticSql-result.xml"); }
From source file:com.appeligo.amazon.ProgramIndexer.java
private void close(ResultSet rs) { if (rs != null) { try {/*from w w w .j a va 2s .co m*/ rs.close(); } catch (SQLException e) { log.warn("Cannot close result set.", e); } } }
From source file:com.redhat.victims.database.VictimsSQL.java
protected boolean isSetUp(Connection connection) throws SQLException { boolean result = false; DatabaseMetaData dbm = connection.getMetaData(); ResultSet rs = dbm.getTables(null, null, "RECORDS", null); result = rs.next();//from w w w . j av a 2 s . c om rs.close(); return result; }
From source file:edu.umass.cs.gnsclient.client.util.keystorage.SimpleKeyStore.java
private void safelyClose(ResultSet rs) { try {// www. j a v a 2s . com if (rs != null) { rs.close(); } } catch (SQLException e) { DerbyControl.printSQLException(e); } }
From source file:me.eccentric_nz.plugins.FatPort.FatPortCmdUtils.java
public String getCommand(int pid, String name) { String command = ""; try {/*from ww w . jav a2 s . c o m*/ Connection connection = service.getConnection(); Statement statement = connection.createStatement(); String queryCmd = "SELECT * FROM commands WHERE p_id = " + pid + " ORDER BY RANDOM()"; ResultSet rsCmd = statement.executeQuery(queryCmd); String tmp = rsCmd.getString("command"); portCommand.put(name, rsCmd.getInt("c_id")); command = StringUtils.replace(tmp, "@p", name); rsCmd.close(); statement.close(); } catch (SQLException e) { plugin.debug("Could not get command! " + e); } return command; }