protected void returnConnectionToDataSource(Connection connection){ JDBC.closeConnection(connection); }
public static void closeStatementAndConnection(Statement statement){ if(null != statement){ Connection conn = null; try{ conn = statement.getConnection(); }catch(Throwable e) { ; } try { statement.close(); } catch (Throwable e) { log.warn("Error closing statement : {} ",e.getMessage(),e); }finally{ closeConnection(conn); } } }
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); } } }
void closeReal() { if(null != conn) { JDBC.closeConnection(conn); conn = null; if(log.isDebugEnabled()) { String state = pool.getStateInfo(); log.debug("Underlying connection closed! {} : [{}]", pool.getName(), state); } } }
@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); } }); }
@Override public void execute(ConnectionCallback callback) throws NestedSQLException { try { DataSource contextDataSource = getContextDataSource(); if(null == contextDataSource && null != tp) { tp.execute(callback); }else{ Connection conn = null; try { conn = null != contextDataSource ? contextDataSource.getConnection() : dataSource.getConnection(); callback.execute(conn); }catch(SQLException e) { throw new NestedSQLException(e, metadata.getProductName()); }finally{ JDBC.closeConnection(conn); } } } finally { SqlExecutionContext.clean(); } }
@Override public <T> T executeWithResult(ConnectionCallbackWithResult<T> callback) throws NestedSQLException { try { DataSource contextDataSource = getContextDataSource(); if(null == contextDataSource && null != tp) { return tp.executeWithResult(callback); }else{ Connection conn = null; try { conn = null != contextDataSource ? contextDataSource.getConnection() : dataSource.getConnection(); return callback.execute(conn); }catch(SQLException e) { throw new NestedSQLException(e, metadata.getProductName()); }finally{ JDBC.closeConnection(conn); } } } finally { SqlExecutionContext.clean(); } }
throw new NestedSQLException("Error creating Db instance : " + e.getMessage(),e); }finally{ JDBC.closeConnection(connection);