public static void close(boolean autoCommitValue, Connection c) { try { if (c != null) { c.setAutoCommit(autoCommitValue); } } catch (SQLException ex) { } finally { close(c); } }
public static void close(boolean autoCommitValue, int transactionIsolationLevel, Connection c) { try { if (c != null) { c.setAutoCommit(autoCommitValue); if (c.getTransactionIsolation() != transactionIsolationLevel) { c.setTransactionIsolation(transactionIsolationLevel); } } } catch (SQLException ex) { } finally { close(c); } }
public List<String> execute(Connection connection) throws SQLException { ArrayList<String> types = new ArrayList<String>(); DatabaseMetaData meta = connection.getMetaData(); ResultSet rs = null; try { rs = meta.getTableTypes(); while (rs.next()) { types.add(rs.getString(1)); } return types; } finally { JdbcSqlTemplate.close(rs); } } });
public Integer execute(Connection con) throws SQLException { Statement stmt = null; ResultSet rs = null; try { logSql(sql, null); stmt = con.createStatement(); if (stmt.execute(sql)) { rs = stmt.getResultSet(); while (rs.next()) { } } return stmt.getUpdateCount(); } finally { JdbcSqlTemplate.close(rs); JdbcSqlTemplate.close(stmt); } } });
public List<String> execute(Connection connection) throws SQLException { ArrayList<String> catalogs = new ArrayList<String>(); DatabaseMetaData meta = connection.getMetaData(); ResultSet rs = null; try { rs = meta.getCatalogs(); while (rs.next()) { catalogs.add(rs.getString(1)); } return catalogs; } finally { JdbcSqlTemplate.close(rs); } } });
public void prepare(String sql) { try { if (this.markers.size() > 0) { throw new IllegalStateException( "Cannot prepare a new batch before the last batch has been flushed."); } JdbcSqlTemplate.close(pstmt); if (log.isDebugEnabled()) { log.debug("Preparing: {}", sql); } pstmt = connection.prepareStatement(sql); psql = sql; } catch (SQLException ex) { throw jdbcSqlTemplate.translate(ex); } }
protected void setPrimaryKeyConstraintName(Connection connection, Table table) throws SQLException { String sql = "select RDB$CONSTRAINT_NAME from RDB$RELATION_CONSTRAINTS where RDB$RELATION_NAME=? and RDB$CONSTRAINT_TYPE='PRIMARY KEY'"; PreparedStatement pstmt = null; try { pstmt = connection.prepareStatement(sql); pstmt.setString(1, table.getName()); ResultSet rs = pstmt.executeQuery(); if (rs.next()) { table.setPrimaryKeyConstraintName(rs.getString(1).trim()); } rs.close(); } finally { JdbcSqlTemplate.close(pstmt); } }
public Integer execute(Connection con) throws SQLException { PreparedStatement stmt = null; ResultSet rs = null; try { logSql(sql, args); stmt = con.prepareStatement(sql); if (args != null && args.length > 0) { jdbcSqlTemplate.setValues(stmt, args); } if (stmt.execute()) { rs = stmt.getResultSet(); while (rs.next()) { } } return stmt.getUpdateCount(); } finally { JdbcSqlTemplate.close(rs); JdbcSqlTemplate.close(stmt); } } });
protected void setPrimaryKeyConstraintName(Connection connection, Table table) throws SQLException { String sql = "select conname from pg_constraint where conrelid in (select oid from pg_class where relname=? and relnamespace in (select oid from pg_namespace where nspname=?)) and contype='p'"; PreparedStatement pstmt = null; ResultSet rs = null; try { pstmt = connection.prepareStatement(sql); pstmt.setString(1, table.getName()); pstmt.setString(2, table.getSchema()); rs = pstmt.executeQuery(); if (rs.next()) { table.setPrimaryKeyConstraintName(rs.getString(1).trim()); } } finally { JdbcSqlTemplate.close(rs); JdbcSqlTemplate.close(pstmt); } }
public Integer execute(Connection con) throws SQLException { PreparedStatement stmt = null; ResultSet rs = null; try { logSql(sql, args); stmt = con.prepareStatement(sql); jdbcSqlTemplate.setValues(stmt, args, types, jdbcSqlTemplate.getLobHandler().getDefaultHandler()); if (stmt.execute()) { rs = stmt.getResultSet(); while (rs.next()) { } } return stmt.getUpdateCount(); } finally { JdbcSqlTemplate.close(rs); JdbcSqlTemplate.close(stmt); } } });
public String execute(Connection con) throws SQLException { String result = null; PreparedStatement ps = null; ResultSet rs = null; try { ps = con.prepareStatement(sql); ps.setQueryTimeout(settings.getQueryTimeout()); setValues(ps, args); rs = ps.executeQuery(); if (rs.next()) { result = lobHandler.getClobAsString(rs, 1); } } finally { close(rs); close(ps); } return result; } });
public T execute(Connection con) throws SQLException { T result = null; PreparedStatement ps = null; ResultSet rs = null; try { ps = con.prepareStatement(expandSql(sql, args)); ps.setQueryTimeout(settings.getQueryTimeout()); setValues(ps, expandArgs(sql, args)); rs = ps.executeQuery(); if (rs.next()) { result = getObjectFromResultSet(rs, clazz); } } finally { close(rs); close(ps); } return result; } });
public T execute(Connection con) throws SQLException { T result = null; Statement stmt = null; ResultSet rs = null; try { logSql(sql, args); if (args != null && args.length > 0) { PreparedStatement ps = con.prepareStatement(sql); stmt = ps; stmt.setQueryTimeout(jdbcSqlTemplate.getSettings().getQueryTimeout()); jdbcSqlTemplate.setValues(ps, args); rs = ps.executeQuery(); } else { stmt = con.createStatement(); stmt.setQueryTimeout(jdbcSqlTemplate.getSettings().getQueryTimeout()); rs = stmt.executeQuery(sql); } if (rs.next()) { result = jdbcSqlTemplate.getObjectFromResultSet(rs, clazz); } } finally { JdbcSqlTemplate.close(rs); JdbcSqlTemplate.close(stmt); } return result; } });
public Integer execute(Connection con) throws SQLException { if (args == null) { Statement stmt = null; try { stmt = con.createStatement(); stmt.setQueryTimeout(settings.getQueryTimeout()); stmt.execute(sql); return stmt.getUpdateCount(); } finally { close(stmt); } } else { PreparedStatement ps = null; try { ps = con.prepareStatement(sql); ps.setQueryTimeout(settings.getQueryTimeout()); if (types != null) { setValues(ps, args, types, getLobHandler() .getDefaultHandler()); } else { setValues(ps, args); } ps.execute(); return ps.getUpdateCount(); } finally { close(ps); } } } });
public <T> T execute(IConnectionCallback<T> callback) { Connection c = null; try { c = getConnection(); return callback.execute(c); } catch (SQLException ex) { throw translate(ex); } finally { close(c); } }
public byte[] execute(Connection con) throws SQLException { if (lobHandler.needsAutoCommitFalseForBlob(jdbcTypeCode, jdbcTypeName)) { con.setAutoCommit(false); } byte[] result = null; PreparedStatement ps = null; ResultSet rs = null; try { ps = con.prepareStatement(sql); ps.setQueryTimeout(settings.getQueryTimeout()); setValues(ps, args); rs = ps.executeQuery(); if (rs.next()) { result = lobHandler.getBlobAsBytes(rs, 1, jdbcTypeCode, jdbcTypeName); } } finally { if (lobHandler.needsAutoCommitFalseForBlob(jdbcTypeCode, jdbcTypeName) && con != null) { con.setAutoCommit(true); } close(rs); close(ps); } return result; } });
public List<T> execute(Connection c) throws SQLException { PreparedStatement st = null; ResultSet rs = null; try { logSql(sql, args); st = c.prepareStatement(sql); st.setQueryTimeout(jdbcSqlTemplate.getSettings().getQueryTimeout()); if (args != null) { jdbcSqlTemplate.setValues(st, args, types, jdbcSqlTemplate.getLobHandler().getDefaultHandler()); } st.setFetchSize(jdbcSqlTemplate.getSettings().getFetchSize()); rs = st.executeQuery(); List<T> list = new ArrayList<T>(); while (rs.next()) { Row row = JdbcSqlReadCursor.getMapForRow(rs, jdbcSqlTemplate.getSettings().isReadStringsAsBytes()); T value = mapper.mapRow(row); list.add(value); } return list; } finally { JdbcSqlTemplate.close(rs); JdbcSqlTemplate.close(st); } } });