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.concursive.connect.web.modules.activity.utils.ProjectHistoryUtils.java
public static int findNextThreadPosition(Connection db, ProjectHistory parentProjectHistory) throws SQLException { int count = 0; PreparedStatement pst = db/*from w w w.jav a 2 s. c o m*/ .prepareStatement("SELECT count(*) AS ccount " + "FROM project_history " + "WHERE lineage LIKE ? "); pst.setString(1, parentProjectHistory.getLineage() + parentProjectHistory.getId() + "/%"); ResultSet rs = pst.executeQuery(); if (rs.next()) { count = rs.getInt("ccount"); } rs.close(); pst.close(); return (parentProjectHistory.getThreadPosition() + count + 1); }
From source file:jdbc.JdbcUtils.java
/** * Close the given JDBC ResultSet and ignore any thrown exception. This is * useful for typical finally blocks in manual JDBC code. * //w ww.j av a 2 s.c o m * @param rs * the JDBC ResultSet to close (may be <code>null</code>) */ public static void closeResultSet(ResultSet rs) { if (rs != null) { try { rs.close(); rs = null; } catch (SQLException ex) { logger.warn("Could not close JDBC ResultSet", ex); } catch (Throwable ex) { // We don't trust the JDBC driver: It might throw // RuntimeException or Error. logger.error("Unexpected exception on closing JDBC ResultSet", ex); } } }
From source file:com.concursive.connect.web.modules.activity.utils.ProjectHistoryUtils.java
public static int findNextPosition(Connection db, int projectHistoryId) throws SQLException { int position = 0; PreparedStatement pst = db.prepareStatement("SELECT max(position) AS position " + "FROM project_history " + "WHERE history_id = ? OR top_id = ? "); pst.setInt(1, projectHistoryId);//from w ww. j av a 2 s. c o m pst.setInt(2, projectHistoryId); ResultSet rs = pst.executeQuery(); if (rs.next()) { position = rs.getInt("position"); } rs.close(); pst.close(); return (position + 1); }
From source file:com.concursive.connect.web.modules.activity.utils.ProjectHistoryUtils.java
public static int queryAdditionalCommentsCount(Connection db, ProjectHistory projectHistory) throws SQLException { int count = 0; int topId = projectHistory.getTopId(); if (topId == -1) { topId = projectHistory.getId();//w w w. ja v a 2 s. c om } PreparedStatement pst = db.prepareStatement("SELECT count(*) AS comment_count " + "FROM project_history " + "WHERE top_id = ? AND position > ? "); pst.setInt(1, topId); pst.setInt(2, projectHistory.getPosition()); ResultSet rs = pst.executeQuery(); if (rs.next()) { count = rs.getInt("comment_count"); } rs.close(); pst.close(); return count; }
From source file:com.wso2telco.dep.subscriptionvalidator.util.ValidatorDBUtils.java
private static void closeResultSet(ResultSet resultSet) { if (resultSet != null) { try {/*from w w w . j a va 2 s . co m*/ resultSet.close(); } catch (SQLException var2) { log.warn("Database error. Could not close ResultSet - " + var2.getMessage(), var2); } } }
From source file:demo.learn.shiro.util.SqlUtil.java
/** * Quietly closes JDBC objects (exceptions are swallowed). * @param conn {@link Connection}.//from w ww.j a va2 s. co m * @param stmt {@link Statement}. * @param rs {@link ResultSet}. */ public static void closeQuietly(Connection conn, Statement stmt, ResultSet rs) { if (null != rs) { try { rs.close(); rs = null; } catch (Exception ex) { } } if (null != stmt) { try { stmt.close(); stmt = null; } catch (Exception ex) { } } if (null != conn) { try { conn.close(); conn = null; } catch (Exception ex) { } } }
From source file:edu.arizona.rice.kew.docsearch.dao.impl.DocumentSearchUtils.java
public static void closeDbObjects(Connection conn, Statement stmt, ResultSet res) { try {/*from w w w .j a va 2 s. co m*/ if (res != null) { res.close(); } } catch (Exception ex) { } try { if (stmt != null) { stmt.close(); } } catch (Exception ex) { } try { if (conn != null) { conn.close(); } } catch (Exception ex) { } }
From source file:com.tacitknowledge.util.migration.jdbc.util.SqlUtil.java
/** * Ensures the given connection, statement, and result are properly closed. * * @param conn the connection to close; may be <code>null</code> * @param stmt the statement to close; may be <code>null</code> * @param rs the result set to close; may be <code>null</code> *///from w w w.j a va 2 s. com public static void close(Connection conn, Statement stmt, ResultSet rs) { if (rs != null) { try { log.debug("Closing ResultSet: " + rs.toString()); rs.close(); } catch (SQLException e) { log.error("Error closing ResultSet", e); } } if (stmt != null) { try { log.debug("Closing Statement: " + stmt.toString()); stmt.close(); } catch (SQLException e) { log.error("Error closing Statement", e); } } if (conn != null) { try { if (!conn.isClosed()) { log.debug("Closing Connection " + conn.toString()); conn.close(); } else { log.debug("Connection (" + conn.toString() + ") already closed."); } } catch (SQLException e) { log.error("Error closing Connection", e); } } }
From source file:at.molindo.dbcopy.util.Utils.java
public static <T> T handle(ResultSet rs, ResultSetHandler<T> handler) throws SQLException { try {//from w w w. j a v a 2s. co m return handler == null ? null : handler.handle(rs); } finally { rs.close(); } }
From source file:com.test.db.MySqlConnection.java
/** * Closes active MySQL connection/*ww w. j a va 2 s .c o m*/ * * @param resultSet the active connection */ public static void close(ResultSet resultSet) { if (resultSet == null) return; try { if (resultSet.isClosed()) return; resultSet.close(); } catch (SQLException e) { LOGGER.error(e.getMessage(), e); } }