@Override public void close() throws SQLException { JDBC.closeStatementOnly(stmt); super.close(); } }
public static void closeResultSetAndStatement(ResultSet rs) { Statement stmt = null; if(null != rs){ try { stmt = rs.getStatement(); } catch (Throwable e) { log.error(e); } try { rs.close(); } catch (Throwable e) { log.warn("Error closing result set : {} ",e.getMessage(),e); } finally { closeStatementOnly(stmt); } } }
public static void closeResultSetAndConnection(ResultSet rs) { if(null != rs){ Connection conn = null; Statement stmt = null; try{ stmt = rs.getStatement(); conn = stmt.getConnection(); }catch(Throwable e){ ; } try { rs.close(); } catch (Throwable e) { log.warn("Error closing result set : {} ",e.getMessage(),e); } finally { closeStatementOnly(stmt); closeConnection(conn); } } }
protected boolean testDriverSupportsGetParameterType() { return db.executeWithResult(connection -> { PreparedStatement ps = null; try { ps = connection.prepareStatement(getTestDriverSupportsGetParameterTypeSQL()); ps.getParameterMetaData().getParameterType(1); return true; } catch (SQLException e) { log.debug("JDBC 3.0 getParameterType call not supported, message : {}", e.getMessage()); return false; } finally { JDBC.closeStatementOnly(ps); } }); }
@Override public void postExecuteUpdate(Db db, Connection connection, PreparedStatement ps, int updatedResult) throws SQLException { PreparedStatement ps1 = null; ResultSet rs = null; try{ ps1 = connection.prepareStatement(db.getDialect().getSelectCurrentSequenceValueSql(sequenceName)); rs = ps1.executeQuery(); if(rs.next()){ generatedIdCallback.accept(db.getDialect().getColumnValue(rs, 1)); }else{ throw new IllegalStateException("No current value of sequence '" + sequenceName + "' returned"); } }finally{ JDBC.closeResultSetOnly(rs); JDBC.closeStatementOnly(ps1); try { if(this.autoCommit){ connection.setAutoCommit(true); } } catch (Exception e) { log.warn("Error restoring the auto comment property of connection : " + e.getMessage(),e); } } } }
@Override public void loadProperties(AppPropertySetter props) { Try.throwUnchecked(() -> { log.info("Load properties from db : {}", jdbcUrl); Class.forName(driverClassName); Statement stmt = null; ResultSet rs = null; Connection conn = null; try { log.debug("Obtain db connection..."); conn = DriverManager.getConnection(jdbcUrl, username, password); log.debug("Execute sql ->\n{}\n", sql); stmt = conn.createStatement(); rs = stmt.executeQuery(sql); int count = 0; while (rs.next()) { String key = rs.getString(1); String value = rs.getString(2); props.putProperty(this, key, value); count++; } log.info("Load {} properties from db!", count); } finally { JDBC.closeResultSetOnly(rs); JDBC.closeStatementOnly(stmt); JDBC.closeConnection(conn); } }); }
throw new NestedSQLException("Error executing this execution : " + e.getMessage(), e); }finally{ JDBC.closeStatementOnly(stmt);
throw new NestedSQLException(e, metadata.getProductName()); }finally{ JDBC.closeStatementOnly(ps);
}finally{ JDBC.closeResultSetOnly(rs); JDBC.closeStatementOnly(ps);
throw new NestedSQLException(e, metadata.getProductName()); }finally{ JDBC.closeStatementOnly(ps);