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:com.l2jfree.sql.L2DatabaseInstaller.java
private static double getDatabaseRevision() { double revision = -1; Connection con = null;/* w w w .j a v a 2 s . c o m*/ try { con = L2Database.getConnection(); Statement st = con.createStatement(); ResultSet rs = st.executeQuery("SELECT revision FROM _revision ORDER BY revision DESC LIMIT 1"); if (rs.next()) revision = rs.getDouble(1); rs.close(); st.close(); } catch (SQLException e) { e.printStackTrace(); } finally { L2Database.close(con); } return revision; }
From source file:com.example.querybuilder.server.Jdbc.java
public static void close(ResultSet resultSet) { try {/*from w w w.j a v a 2s. c om*/ resultSet.close(); } catch (SQLException e) { throw new SqlRuntimeException(e); } }
From source file:com.nokia.helium.metadata.DerbyFactoryManagerCreator.java
/** * Checks the database integrity./*from w w w .j av a 2 s.c om*/ * @param urlPath - database path to be connected to. * @return boolean - true if db is valid false otherwise. */ private static boolean checkDatabaseIntegrity(File database) throws MetadataException { boolean result = false; Connection connection = null; try { connection = DriverManager.getConnection("jdbc:derby:" + database); if (connection != null) { Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery("select version from version"); int version = -1; if (rs.next()) { version = rs.getInt(1); } rs.close(); stmt.close(); connection.close(); connection = null; result = version == Version.DB_VERSION; } } catch (SQLException ex) { try { DriverManager.getConnection("jdbc:derby:;shutdown=true"); } catch (java.sql.SQLException sex) { // normal exception during database shutdown connection = null; } return false; } finally { try { if (connection != null) { connection.close(); } } catch (java.sql.SQLException sex) { // normal exception during database shutdown connection = null; } connection = null; if (!result) { try { DriverManager.getConnection("jdbc:derby:;shutdown=true"); } catch (java.sql.SQLException sex) { // normal exception during database shutdown connection = null; } } } //shutdown unloads the driver, driver need to be loaded again. return result; }
From source file:ips1ap101.lib.core.db.util.DB.java
public static boolean close(ResultSet resultSet) { if (resultSet != null) { try {//www . ja v a 2s . c o m resultSet.close(); return true; } catch (SQLException ex) { Bitacora.logFatal(ex); } } return false; }
From source file:localdomain.localhost.CasInitializer.java
public static void closeQuietly(ResultSet rst) { if (rst == null) return;//from w ww . j av a 2 s . com try { rst.close(); } catch (Exception e) { // ignore } }
From source file:com.chaosinmotion.securechat.server.commands.RemoveDevice.java
public static boolean processRequest(Login.UserInfo userinfo, JSONObject requestParams) throws ClassNotFoundException, SQLException, IOException { String deviceid = requestParams.optString("deviceid"); /*// www . j a va 2 s. co m * Delete device. We only delete if it is also ours. */ Connection c = null; PreparedStatement ps = null; ResultSet rs = null; try { c = Database.get(); ps = c.prepareStatement("DELETE FROM Devices " + "WHERE userid = ? AND deviceuuid = ?"); ps.setInt(1, userinfo.getUserID()); ps.setString(2, deviceid); ps.execute(); return true; } finally { if (rs != null) rs.close(); if (ps != null) ps.close(); if (c != null) c.close(); } }
From source file:net.sf.jabb.util.db.ConnectionUtility.java
/** * Closes database ResultSet// w ww. j av a 2 s .c om * No exception will be thrown even if occurred during closing, * instead, the exception will be logged at warning level. * * @param rs the ResultSet that need to be closed */ public static void closeResultSet(ResultSet rs) { if (rs != null) { try { rs.close(); } catch (Exception e) { log.warn("Exception when closing database result set.", e); } } }
From source file:com.chiralbehaviors.CoRE.kernel.KernelUtil.java
public static void clear(EntityManager em) throws SQLException { Connection connection = em.unwrap(Connection.class); connection.setAutoCommit(false);//from ww w.j av a 2 s . co m alterTriggers(connection, false); ResultSet r = connection.createStatement().executeQuery(KernelUtil.SELECT_TABLE); while (r.next()) { String table = r.getString("name"); String query = String.format("DELETE FROM %s", table); connection.createStatement().execute(query); } r.close(); alterTriggers(connection, true); CACHED_KERNEL.set(null); connection.commit(); }
From source file:Main.java
public static byte[] getBLOB(int id, Connection conn) throws Exception { ResultSet rs = null; PreparedStatement pstmt = null; String query = "SELECT photo FROM MyPictures WHERE id = ?"; try {/*w w w.ja va 2 s . c o m*/ pstmt = conn.prepareStatement(query); pstmt.setInt(1, id); rs = pstmt.executeQuery(); rs.next(); Blob blob = rs.getBlob(3); // materialize BLOB onto client return blob.getBytes(1, (int) blob.length()); } finally { rs.close(); pstmt.close(); conn.close(); } }
From source file:Main.java
public static byte[] getBLOB(int id, Connection conn) throws Exception { ResultSet rs = null; PreparedStatement pstmt = null; String query = "SELECT photo FROM MyPictures WHERE id = ?"; try {/*from w w w . j a va2 s . co m*/ pstmt = conn.prepareStatement(query); pstmt.setInt(1, id); rs = pstmt.executeQuery(); rs.next(); Blob blob = rs.getBlob("photo"); // materialize BLOB onto client return blob.getBytes(1, (int) blob.length()); } finally { rs.close(); pstmt.close(); conn.close(); } }