Statement statement = null; try { statement = getStatement(connection, sql); boolean isResultSet = statement.execute(sql); this.updateCount = statement.getUpdateCount();
/** * Executes the given SQL update. * <p> * Resource handling is performed automatically where appropriate. * * @param sql the SQL to execute * @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) throws SQLException { Connection connection = createConnection(); Statement statement = null; try { statement = getStatement(connection, sql); this.updateCount = statement.executeUpdate(sql); return this.updateCount; } catch (SQLException e) { LOG.warning("Failed to execute: " + sql + " because: " + e.getMessage()); throw e; } finally { closeResources(connection, statement); } }
/** * Executes the given SQL update. * <p/> * Resource handling is performed automatically where appropriate. * * @param sql the SQL to execute * @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) throws SQLException { Connection connection = createConnection(); Statement statement = null; try { statement = getStatement(connection, sql); this.updateCount = statement.executeUpdate(sql); return this.updateCount; } catch (SQLException e) { LOG.warning("Failed to execute: " + sql + " because: " + e.getMessage()); throw e; } finally { closeResources(connection, statement); } }
/** * Executes the given SQL update. * * @param sql the SQL to execute * @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) throws SQLException { Connection connection = createConnection(); Statement statement = null; try { log.fine(sql); statement = getStatement(connection, sql); this.updateCount = statement.executeUpdate(sql); return this.updateCount; } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement); } }
/** * Performs the given SQL query and return the rows of the result set. * * @param sql the SQL statement * @param metaClosure called with meta data of the ResultSet * @return a list of GroovyRowResult objects * @throws SQLException if a database access error occurs */ public List rows(String sql, Closure metaClosure) throws SQLException { List<GroovyRowResult> results = new ArrayList<GroovyRowResult>(); Connection connection = createConnection(); Statement statement = getStatement(connection, sql); configure(statement); ResultSet rs = null; try { log.fine(sql); rs = statement.executeQuery(sql); if (metaClosure != null) metaClosure.call(rs.getMetaData()); while (rs.next()) { results.add(DefaultGroovyMethods.toRowResult(rs)); } return (results); } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement, rs); } }
/** * Executes the given piece of SQL. * * @param sql the SQL to execute * @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) throws SQLException { Connection connection = createConnection(); Statement statement = null; try { log.fine(sql); statement = getStatement(connection, sql); configure(statement); boolean isResultSet = statement.execute(sql); this.updateCount = statement.getUpdateCount(); return isResultSet; } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement); } }
Statement statement = getStatement(connection, sql); ResultSet results = null; try {
/** * Executes the given SQL update. * * @param sql the SQL to execute * @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) throws SQLException { Connection connection = createConnection(); Statement statement = null; try { log.fine(sql); statement = getStatement(connection, sql); configure(statement); this.updateCount = statement.executeUpdate(sql); return this.updateCount; } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement); } }
Statement statement = getStatement(connection, sql); ResultSet results = null; try {
/** * Performs the given SQL query calling the closure with the result set. * * @param sql the sql statement * @param closure called for each row with a GroovyResultSet * @throws SQLException if a database access error occurs */ public void query(String sql, Closure closure) throws SQLException { Connection connection = createConnection(); Statement statement = getStatement(connection, sql); configure(statement); ResultSet results = null; try { log.fine(sql); results = statement.executeQuery(sql); closure.call(results); } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement, results); } }
try { log.fine(sql); statement = getStatement(connection, sql);
try { log.fine(sql); statement = getStatement(connection, sql); configure(statement); boolean hasResultSet = statement.execute(sql, Statement.RETURN_GENERATED_KEYS);
ResultSet results = null; try { statement = getStatement(connection, sql); results = statement.executeQuery(sql); closure.call(results);
/** * Executes the given SQL statement (typically an INSERT statement). * Use this variant when you want to receive the values of any * auto-generated columns, such as an autoincrement ID field. * See {@link #executeInsert(GString)} for more details. * <p> * Resource handling is performed automatically where appropriate. * * @param sql The SQL statement to execute * @return A list of the auto-generated column values for each * inserted row (typically auto-generated keys) * @throws SQLException if a database access error occurs */ public List<List<Object>> executeInsert(String sql) throws SQLException { Connection connection = createConnection(); Statement statement = null; try { statement = getStatement(connection, sql); this.updateCount = statement.executeUpdate(sql, Statement.RETURN_GENERATED_KEYS); ResultSet keys = statement.getGeneratedKeys(); return calculateKeys(keys); } catch (SQLException e) { LOG.warning("Failed to execute: " + sql + " because: " + e.getMessage()); throw e; } finally { closeResources(connection, statement); } }
Statement statement = null; try { statement = getStatement(connection, sql); boolean isResultSet = statement.execute(sql); int updateCount = statement.getUpdateCount();
/** * Executes the given SQL statement (typically an INSERT statement). * Use this variant when you want to receive the values of any * auto-generated columns, such as an autoincrement ID field. * See {@link #executeInsert(GString)} for more details. * <p/> * Resource handling is performed automatically where appropriate. * * @param sql The SQL statement to execute * @return A list of the auto-generated column values for each * inserted row (typically auto-generated keys) * @throws SQLException if a database access error occurs */ public List<List<Object>> executeInsert(String sql) throws SQLException { Connection connection = createConnection(); Statement statement = null; try { statement = getStatement(connection, sql); this.updateCount = statement.executeUpdate(sql, Statement.RETURN_GENERATED_KEYS); ResultSet keys = statement.getGeneratedKeys(); return calculateKeys(keys); } catch (SQLException e) { LOG.warning("Failed to execute: " + sql + " because: " + e.getMessage()); throw e; } finally { closeResources(connection, statement); } }
/** * Executes the given SQL statement (typically an INSERT statement). * Use this variant when you want to receive the values of any * auto-generated columns, such as an autoincrement ID field. * See {@link #executeInsert(GString)} for more details. * * @param sql The SQL statement to execute * @return A list of the auto-generated column values for each * inserted row (typically auto-generated keys) * @throws SQLException if a database access error occurs */ public List<List<Object>> executeInsert(String sql) throws SQLException { Connection connection = createConnection(); Statement statement = null; try { log.fine(sql); statement = getStatement(connection, sql); this.updateCount = statement.executeUpdate(sql, Statement.RETURN_GENERATED_KEYS); ResultSet keys = statement.getGeneratedKeys(); return calculateKeys(keys); } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement); } }
/** * Performs the given SQL query calling closures for metadata and each row * * @param sql the sql statement * @param metaClosure called for meta data (only once after sql execution) * @param rowClosure called for each row with a GroovyResultSet * @throws SQLException if a database access error occurs */ public void eachRow(String sql, Closure metaClosure, Closure rowClosure) throws SQLException { Connection connection = createConnection(); Statement statement = getStatement(connection, sql); configure(statement); ResultSet results = null; try { log.fine(sql); results = statement.executeQuery(sql); if (metaClosure != null) metaClosure.call(results.getMetaData()); GroovyResultSet groovyRS = new GroovyResultSetProxy(results).getImpl(); while (groovyRS.next()) { rowClosure.call(groovyRS); } } catch (SQLException e) { log.log(Level.FINE, "Failed to execute: " + sql, e); throw e; } finally { closeResources(connection, statement, results); } }
/** * Executes the given SQL statement (typically an INSERT statement). * This variant allows you to receive the values of any auto-generated columns, * such as an autoincrement ID field (or fields) when you know the column name(s) of the ID field(s). * <p> * This method supports named and named ordinal parameters by supplying such * parameters in the <code>params</code> array. See the class Javadoc for more details. * * @param sql The SQL statement to execute * @param keyColumnNames an array of column names indicating the columns that should be returned from the * inserted row or rows (some drivers may be case sensitive, e.g. may require uppercase names) * @return A list of the auto-generated row results for each inserted row (typically auto-generated keys) * @throws SQLException if a database access error occurs * @since 2.3.2 */ public List<GroovyRowResult> executeInsert(String sql, String[] keyColumnNames) throws SQLException { Connection connection = createConnection(); Statement statement = null; try { statement = getStatement(connection, sql); this.updateCount = statement.executeUpdate(sql, keyColumnNames); ResultSet keys = statement.getGeneratedKeys(); return asList(sql, keys); } catch (SQLException e) { LOG.warning("Failed to execute: " + sql + " because: " + e.getMessage()); throw e; } finally { closeResources(connection, statement); } }
Statement statement = getStatement(connection, sql); ResultSet results = null; try {