public void addBatch(List<Object> parameters) throws SQLException { if (indexPropList != null) { sql.setParameters(sql.getUpdatedParams(parameters, indexPropList), delegate); } else { sql.setParameters(parameters, delegate); } delegate.addBatch(); incrementBatchCount(); } }
public void addBatch(List<Object> parameters) throws SQLException { if (indexPropList != null) { sql.setParameters(sql.getUpdatedParams(parameters, indexPropList), delegate); } else { sql.setParameters(parameters, delegate); } delegate.addBatch(); incrementBatchCount(); } }
public void addBatch(List<Object> parameters) throws SQLException { if (indexPropList != null) { sql.setParameters(sql.getUpdatedParams(parameters, indexPropList), delegate); } else { sql.setParameters(parameters, delegate); } delegate.addBatch(); batchCount++; if (batchCount == batchSize /* never true for batchSize of 0 */) { int[] result = delegate.executeBatch(); processResult(result); batchCount = 0; } } }
private CallableStatement getCallableStatement(Connection connection, String sql, List<Object> params) throws SQLException { LOG.fine(sql + " | " + params); CallableStatement statement = (CallableStatement) getAbstractStatement(new CreateCallableStatementCommand(), connection, sql); setParameters(params, statement); configure(statement); return statement; }
/** * Executes the given piece of SQL with parameters. * * @param sql the SQL statement * @param params a list of parameters * @return <code>true</code> if the first result is a <code>ResultSet</code> * object; <code>false</code> if it is an update count or there are * no results * @throws SQLException if a database access error occurs */ public boolean execute(String sql, List params) throws SQLException { Connection connection = createConnection(); PreparedStatement statement = null; try { log.fine(sql); statement = connection.prepareStatement(sql); setParameters(params, statement); configure(statement); boolean isResultSet = statement.execute(); this.updateCount = statement.getUpdateCount(); return isResultSet; } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement); } }
/** * Performs the given SQL query with parameters calling the closure with the * result set. * * @param sql the sql statement * @param params a list of parameters * @param closure called for each row with a GroovyResultSet * @throws SQLException if a database access error occurs */ public void query(String sql, List params, Closure closure) throws SQLException { Connection connection = createConnection(); PreparedStatement statement = null; ResultSet results = null; try { log.fine(sql); statement = connection.prepareStatement(sql); setParameters(params, statement); configure(statement); results = statement.executeQuery(); closure.call(results); } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement, results); } }
/** * Executes the given SQL update with parameters. * * @param sql the SQL statement * @param params a list of parameters * @return the number of rows updated or 0 for SQL statements that return nothing * @throws SQLException if a database access error occurs */ public int executeUpdate(String sql, List params) throws SQLException { Connection connection = createConnection(); PreparedStatement statement = null; try { log.fine(sql); statement = connection.prepareStatement(sql); setParameters(params, statement); configure(statement); this.updateCount = statement.executeUpdate(); return this.updateCount; } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement); } }
log.fine(sql); statement = connection.prepareStatement(sql); setParameters(params, statement); configure(statement); rs = statement.executeQuery();
private PreparedStatement getPreparedStatement(Connection connection, String sql, List<Object> params, int returnGeneratedKeys) throws SQLException { PreparedStatement statement = (PreparedStatement) getAbstractStatement(new CreatePreparedStatementCommand(returnGeneratedKeys), connection, sql); setParameters(params, statement); configure(statement); return statement; }
/** * Performs the given SQL query with parameters calling the closure with the * result set. * * @param sql the sql statement * @param params a list of parameters * @param closure called for each row with a GroovyResultSet * @throws SQLException if a database access error occurs */ public void query(String sql, List params, Closure closure) throws SQLException { Connection connection = createConnection(); PreparedStatement statement = null; ResultSet results = null; try { log.fine(sql); statement = getPreparedStatement(connection, sql); setParameters(params, statement); configure(statement); results = statement.executeQuery(); closure.call(results); } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement, results); } }
/** * Performs a stored procedure call with the given parameters. * * @param sql the SQL statement * @param params a list of parameters * @return the number of rows updated or 0 for SQL statements that return nothing * @throws SQLException if a database access error occurs */ public int call(String sql, List params) throws Exception { Connection connection = createConnection(); CallableStatement statement = connection.prepareCall(sql); try { log.fine(sql); setParameters(params, statement); configure(statement); return statement.executeUpdate(); } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement); } }
/** * Executes the given piece of SQL with parameters. * * @param sql the SQL statement * @param params a list of parameters * @return <code>true</code> if the first result is a <code>ResultSet</code> * object; <code>false</code> if it is an update count or there are * no results * @throws SQLException if a database access error occurs */ public boolean execute(String sql, List params) throws SQLException { Connection connection = createConnection(); PreparedStatement statement = null; try { log.fine(sql); statement = getPreparedStatement(connection, sql); setParameters(params, statement); configure(statement); boolean isResultSet = statement.execute(); this.updateCount = statement.getUpdateCount(); return isResultSet; } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement); } }
/** * Performs a stored procedure call with the given parameters. * * @param sql the SQL statement * @param params a list of parameters * @return the number of rows updated or 0 for SQL statements that return nothing * @throws SQLException if a database access error occurs */ public int call(String sql, List params) throws Exception { Connection connection = createConnection(); CallableStatement statement = connection.prepareCall(sql); try { log.fine(sql); setParameters(params, statement); configure(statement); return statement.executeUpdate(); } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement); } }
log.fine(sql); statement = getPreparedStatement(connection, sql); setParameters(params, statement); configure(statement); rs = statement.executeQuery();
try { LOG.fine(sql + " | " + params); setParameters(params, statement); configure(statement); return statement.executeUpdate();
/** * Executes the given SQL update with parameters. * * @param sql the SQL statement * @param params a list of parameters * @return the number of rows updated or 0 for SQL statements that return nothing * @throws SQLException if a database access error occurs */ public int executeUpdate(String sql, List params) throws SQLException { Connection connection = createConnection(); PreparedStatement statement = null; try { log.fine(sql); statement = getPreparedStatement(connection, sql); setParameters(params, statement); configure(statement); this.updateCount = statement.executeUpdate(); return this.updateCount; } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement); } }
log.fine(sql); statement = connection.prepareStatement(sql); setParameters(params, statement); configure(statement); results = statement.executeQuery();
log.fine(sql); statement = getPreparedStatement(connection, sql); setParameters(params, statement); configure(statement); results = statement.executeQuery();
private PreparedStatement getPreparedStatement(Connection connection, String sql, List<Object> params, int returnGeneratedKeys) throws SQLException { SqlWithParams updated = checkForNamedParams(sql, params); LOG.fine(updated.getSql() + " | " + updated.getParams()); PreparedStatement statement = (PreparedStatement) getAbstractStatement(new CreatePreparedStatementCommand(returnGeneratedKeys), connection, updated.getSql()); setParameters(updated.getParams(), statement); configure(statement); return statement; }
private PreparedStatement getPreparedStatement(Connection connection, String sql, List<Object> params, int returnGeneratedKeys) throws SQLException { SqlWithParams updated = checkForNamedParams(sql, params); LOG.fine(updated.getSql() + " | " + updated.getParams()); PreparedStatement statement = (PreparedStatement) getAbstractStatement(new CreatePreparedStatementCommand(returnGeneratedKeys), connection, updated.getSql()); setParameters(updated.getParams(), statement); configure(statement); return statement; }