dgraham 2003/10/22 16:25:02
Modified: dbutils/src/java/org/apache/commons/dbutils QueryRunner.java
Log:
Removed references to ResultSetMetaDataHandler.
Revision Changes Path
1.8 +382 -520
jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/QueryRunner.java
Index: QueryRunner.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/QueryRunner.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- QueryRunner.java 22 Oct 2003 02:10:23 -0000 1.7
+++ QueryRunner.java 22 Oct 2003 23:25:01 -0000 1.8
@@ -66,9 +66,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
-import java.util.ArrayList;
import java.util.Arrays;
-import java.util.List;
import javax.sql.DataSource;
@@ -86,520 +84,384 @@
*/
public class QueryRunner {
- /**
- * The DataSource to retrieve connections from.
- */
- protected DataSource ds = null;
-
- /**
- * Constructor for QueryRunner.
- */
- public QueryRunner() {
- super();
- }
-
- /**
- * Constructor for QueryRunner. Methods that do not take a
- * <code>Connection</code> parameter will retrieve connections from this
- * <code>DataSource</code>.
- *
- * @param ds The <code>DataSource</code> to retrieve connections from.
- */
- public QueryRunner(DataSource ds) {
- super();
- this.ds = ds;
- }
-
- /**
- * Execute any SQL statement and return all the results in an
- * <code>Object[]</code>. Callers are responsible for connection cleanup.
- *
- * @param conn The connection to execute the query with.
- * @param sql The SQL statement.
- * @param params SQL replacement parameters; <code>null</code> if no
- * parameters are required.
- * @param rsh The handler to generate result objects with
- * @param rsmdh Handles the meta data.
- * @param userObject Object to pass to the handler.
- * @return An array filled with result objects from the handler for each
- * <code>ResultSet</code> returned by the query; <code>null</code> if the
- * statment was an UPDATE.
- * @throws SQLException
- */
- public Object[] execute(
- Connection conn,
- String sql,
- Object[] params,
- ResultSetHandler rsh,
- ResultSetMetaDataHandler rsmdh,
- Object userObject)
- throws SQLException {
-
- PreparedStatement stmt = null;
- ResultSet rs = null;
-
- List results = new ArrayList();
-
- try {
- stmt = conn.prepareStatement(sql);
- this.fillStatement(stmt, params);
-
- if (!stmt.execute()) {
- return null;
- }
-
- do {
- rs = stmt.getResultSet();
- if (rs != null) {
- rs = this.wrap(rs);
-
- if (rsmdh != null) {
- rsmdh.handle(rs.getMetaData());
- }
-
- results.add(rsh.handle(rs, params, userObject));
- }
-
- } while (stmt.getMoreResults());
-
- } catch (SQLException e) {
- rethrow(e, sql, params);
-
- } finally {
- DbUtils.closeQuietly(rs);
- DbUtils.closeQuietly(stmt);
- }
-
- Object[] res = new Object[results.size()];
- return results.toArray(res);
- }
-
- /**
- * Fill the <code>PreparedStatement</code> replacement parameters with
- * the given objects.
- * @param stmt
- * @param params Query replacement parameters; <code>null</code> is a valid
- * value to pass in.
- * @throws SQLException
- */
- protected void fillStatement(PreparedStatement stmt, Object[] params)
- throws SQLException {
-
- if (params == null) {
- return;
- }
-
- for (int i = 0; i < params.length; i++) {
- if (params[i] != null) {
- stmt.setObject(i + 1, params[i]);
- } else {
- stmt.setNull(i + 1, Types.OTHER);
- }
- }
- }
-
- /**
- * Returns the <code>DataSource</code> this runner is using.
- */
- public DataSource getDataSource() {
- return this.ds;
- }
-
- /**
- * Execute an SQL SELECT query with a single replacement parameter. The
- * caller is responsible for connection cleanup.
- *
- * @param conn The connection to execute the query in.
- * @param sql The query to execute.
- * @param param The replacement parameter.
- * @param rsh The handler that converts the results into an object.
- * @return The object returned by the handler.
- * @throws SQLException
- */
- public Object query(
- Connection conn,
- String sql,
- Object param,
- ResultSetHandler rsh)
- throws SQLException {
-
- return this.query(conn, sql, new Object[] { param }, rsh, null, null);
- }
-
- /**
- * Execute an SQL SELECT query without any replacement parameters. The
- * caller is responsible for connection cleanup.
- *
- * @param conn The connection to execute the query in.
- * @param sql The query to execute.
- * @param params The replacement parameters.
- * @param rsh The handler that converts the results into an object.
- * @return The object returned by the handler.
- * @throws SQLException
- */
- public Object query(
- Connection conn,
- String sql,
- Object[] params,
- ResultSetHandler rsh)
- throws SQLException {
-
- return this.query(conn, sql, params, rsh, null, null);
- }
-
- /**
- * Execute an SQL SELECT query with replacement parameters. The
- * caller is responsible for connection cleanup.
- *
- * @param conn The connection to execute the query in.
- * @param sql The query to execute.
- * @param params The replacement parameters.
- * @param rsh The handler that converts the results into an object.
- * @param rsmdh Handles the meta data.
- * @return The object returned by the handler.
- * @throws SQLException
- */
- public Object query(
- Connection conn,
- String sql,
- Object[] params,
- ResultSetHandler rsh,
- ResultSetMetaDataHandler rsmdh)
- throws SQLException {
-
- return this.query(conn, sql, params, rsh, rsmdh, null);
- }
-
- /**
- * Execute an SQL SELECT query with replacement parameters. The
- * caller is responsible for connection cleanup.
- *
- * @param conn The connection to execute the query in.
- * @param sql The query to execute.
- * @param params The replacement parameters.
- * @param rsh The handler that converts the results into an object.
- * @param rsmdh Handles the meta data.
- * @param userObject Pass this object to the handler.
- * @return The object returned by the handler.
- * @throws SQLException
- */
- public Object query(
- Connection conn,
- String sql,
- Object[] params,
- ResultSetHandler rsh,
- ResultSetMetaDataHandler rsmdh,
- Object userObject)
- throws SQLException {
-
- PreparedStatement stmt = null;
- ResultSet rs = null;
- Object result = null;
-
- try {
- stmt = conn.prepareStatement(sql);
- this.fillStatement(stmt, params);
-
- rs = this.wrap(stmt.executeQuery());
-
- if (rsmdh != null) {
- rsmdh.handle(rs.getMetaData());
- }
-
- result = rsh.handle(rs, params, userObject);
-
- } catch (SQLException e) {
- this.rethrow(e, sql, params);
-
- } finally {
- DbUtils.closeQuietly(rs);
- DbUtils.closeQuietly(stmt);
- }
-
- return result;
- }
-
- /**
- * Execute an SQL SELECT query with replacement parameters. The
- * caller is responsible for connection cleanup.
- *
- * @param conn The connection to execute the query in.
- * @param sql The query to execute.
- * @param params The replacement parameters.
- * @param rsdmh Handles the meta data.
- * @return The object returned by the handler.
- * @throws SQLException
- */
- public Object query(
- Connection conn,
- String sql,
- Object[] params,
- ResultSetMetaDataHandler rsmdh)
- throws SQLException {
-
- return this.query(conn, sql, params, null, rsmdh, null);
- }
-
- /**
- * Execute an SQL SELECT query without any replacement parameters. The
- * caller is responsible for connection cleanup.
- *
- * @param conn The connection to execute the query in.
- * @param sql The query to execute.
- * @param rsh The handler that converts the results into an object.
- * @return The object returned by the handler.
- * @throws SQLException
- */
- public Object query(Connection conn, String sql, ResultSetHandler rsh)
- throws SQLException {
-
- return this.query(conn, sql, null, rsh, null, null);
- }
-
- /**
- * Executes the given SELECT SQL with a single replacement parameter.
- * The <code>Connection</code> is retrieved from the
- * <code>DataSource</code> set in the constructor.
- *
- * @param sql The SQL statement to execute.
- * @param rsh The handler used to create the result object from
- * the <code>ResultSet</code>.
- * @param param The replacement parameter.
- * @return An object generated by the handler.
- * @throws SQLException
- */
- public Object query(String sql, Object param, ResultSetHandler rsh)
- throws SQLException {
-
- return this.query(sql, new Object[] { param }, rsh);
- }
-
- /**
- * Executes the given SELECT SQL query and returns a result object.
- * The <code>Connection</code> is retrieved from the
- * <code>DataSource</code> set in the constructor.
- *
- * @param sql The SQL statement to execute.
- * @param params Initialize the PreparedStatement's IN parameters with this
- * array.
- * @param rsh The handler used to create the result object from
- * the <code>ResultSet</code>.
- * @return An object generated by the handler.
- * @throws SQLException
- */
- public Object query(String sql, Object[] params, ResultSetHandler rsh)
- throws SQLException {
-
- Connection conn = this.ds.getConnection();
-
- Object result = null;
-
- try {
- result = this.query(conn, sql, params, rsh, null, null);
-
- } finally {
- DbUtils.close(conn);
- }
-
- return result;
- }
-
- /**
- * Executes the given SELECT SQL without any replacement parameters.
- * The <code>Connection</code> is retrieved from the
- * <code>DataSource</code> set in the constructor.
- *
- * @param sql The SQL statement to execute.
- * @param rsh The handler used to create the result object from
- * the <code>ResultSet</code>.
- * @return An object generated by the handler.
- * @throws SQLException
- */
- public Object query(String sql, ResultSetHandler rsh) throws SQLException {
- return this.query(sql, null, rsh);
- }
-
- /**
- * Throws a new exception with a more informative error message.
- * @param cause The original exception that will be chained to the new
- * exception when it's rethrown.
- * @param sql The query that was executing when the exception happened.
- * @param params The query replacement paramaters; <code>null</code> is a
- * valid value to pass in.
- * @throws SQLException
- */
- protected void rethrow(SQLException cause, String sql, Object[] params)
- throws SQLException {
-
- StringBuffer msg = new StringBuffer(cause.getMessage() + " in query " +
sql);
- if (params != null) {
- msg.append(Arrays.asList(params).toString());
- }
-
- SQLException newsqle = new SQLException(msg.toString());
- newsqle.setNextException(cause);
-
- throw newsqle;
- }
-
- /**
- * Sets the <code>DataSource</code> this runner will use to get
- * database connections from. This should be called after creating a
- * runner with the default constructor if you intend to use the
- * execute methods without passing in a <code>Connection</code>.
- * @param dataSource The DataSource to use.
- */
- public void setDataSource(DataSource dataSource) {
- this.ds = dataSource;
- }
-
- /**
- * Execute an SQL INSERT, UPDATE, or DELETE query without replacement
- * parameters.
- *
- * @param conn The connection to use to run the query.
- * @param sql The SQL to execute.
- * @return The number of rows updated.
- * @throws SQLException
- */
- public int update(Connection conn, String sql) throws SQLException {
- return this.update(conn, sql, null);
- }
-
- /**
- * Execute an SQL INSERT, UPDATE, or DELETE query with a single replacement
- * parameter.
- *
- * @param conn The connection to use to run the query.
- * @param sql The SQL to execute.
- * @param param The replacement parameter.
- * @return The number of rows updated.
- * @throws SQLException
- */
- public int update(Connection conn, String sql, Object param)
- throws SQLException {
-
- return this.update(conn, sql, new Object[] { param });
- }
-
- /**
- * Execute an SQL INSERT, UPDATE, or DELETE query.
- * @param conn The connection to use to run the query.
- * @param sql The SQL to execute.
- * @param params The query replacement parameters.
- * @return The number of rows updated.
- * @throws SQLException
- */
- public int update(Connection conn, String sql, Object[] params)
- throws SQLException {
-
- PreparedStatement stmt = conn.prepareStatement(sql);
- this.fillStatement(stmt, params);
-
- int rows = 0;
-
- try {
- rows = stmt.executeUpdate();
-
- } catch (SQLException e) {
- this.rethrow(e, sql, params);
-
- } finally {
- DbUtils.closeQuietly(stmt);
- }
-
- return rows;
- }
-
- /**
- * Executes the given INSERT, UPDATE, or DELETE SQL statement without
- * any replacement parameters. The statement is executed in it's own
- * transaction that will be committed or rolled back depending on any
- * SQLExceptions thrown. The <code>Connection</code> is retrieved from the
- * <code>DataSource</code> set in the constructor.
- *
- * @param sql The SQL statement to execute.
- * @throws SQLException
- * @return The number of rows updated.
- */
- public int update(String sql) throws SQLException {
- return this.update(sql, null);
- }
-
- /**
- * Executes the given INSERT, UPDATE, or DELETE SQL statement with
- * a single replacement parameter. The statement is executed in it's own
- * transaction that will be committed or rolled back depending on any
- * SQLExceptions thrown. The <code>Connection</code> is retrieved from the
- * <code>DataSource</code> set in the constructor.
- *
- * @param sql The SQL statement to execute.
- * @param param The replacement parameter.
- * @throws SQLException
- * @return The number of rows updated.
- */
- public int update(String sql, Object param) throws SQLException {
- return this.update(sql, new Object[] { param });
- }
-
- /**
- * Executes the given INSERT, UPDATE, or DELETE SQL statement. The
- * statement is executed in it's own transaction that will be committed or
- * rolled back depending on any SQLExceptions thrown. The
- * <code>Connection</code> is retrieved from the <code>DataSource</code>
- * set in the constructor.
- *
- * @param sql The SQL statement to execute.
- * @param params Initializes the PreparedStatement's IN (ie. '?')
- * parameters.
- * @throws SQLException
- * @return The number of rows updated.
- */
- public int update(String sql, Object[] params) throws SQLException {
-
- Connection conn = this.ds.getConnection();
-
- int rows = 0;
-
- try {
- conn.setAutoCommit(false); // single transaction.
- rows = this.update(conn, sql, params);
- conn.commit();
-
- } catch (SQLException e) {
- DbUtils.rollback(conn);
- throw e;
-
- } finally {
- DbUtils.close(conn);
- }
-
- return rows;
- }
-
- /**
- * Wrap the <code>ResultSet</code> in a decorator before processing it.
- * This implementation returns the <code>ResultSet</code> it is given
- * without any decoration.
- *
- * <p>
- * Often, the implementation of this method can be done in an anonymous
- * inner class like this:
- * </p>
- * <pre>
- * QueryRunner run = new QueryRunner() {
- * protected void wrap(ResultSet rs) {
- * return StringTrimmedResultSet.wrap(rs);
- * }
- * };
- * </pre>
- *
- * @param rs The <code>ResultSet</code> to decorate; never
- * <code>null</code>.
- * @return The <code>ResultSet</code> wrapped in some decorator.
- */
- protected ResultSet wrap(ResultSet rs) {
- return rs;
- }
+ /**
+ * The DataSource to retrieve connections from.
+ */
+ protected DataSource ds = null;
+
+ /**
+ * Constructor for QueryRunner.
+ */
+ public QueryRunner() {
+ super();
+ }
+
+ /**
+ * Constructor for QueryRunner. Methods that do not take a
+ * <code>Connection</code> parameter will retrieve connections from this
+ * <code>DataSource</code>.
+ *
+ * @param ds The <code>DataSource</code> to retrieve connections from.
+ */
+ public QueryRunner(DataSource ds) {
+ super();
+ this.ds = ds;
+ }
+
+ /**
+ * Fill the <code>PreparedStatement</code> replacement parameters with
+ * the given objects.
+ * @param stmt
+ * @param params Query replacement parameters; <code>null</code> is a valid
+ * value to pass in.
+ * @throws SQLException
+ */
+ protected void fillStatement(PreparedStatement stmt, Object[] params)
+ throws SQLException {
+
+ if (params == null) {
+ return;
+ }
+
+ for (int i = 0; i < params.length; i++) {
+ if (params[i] != null) {
+ stmt.setObject(i + 1, params[i]);
+ } else {
+ stmt.setNull(i + 1, Types.OTHER);
+ }
+ }
+ }
+
+ /**
+ * Returns the <code>DataSource</code> this runner is using.
+ */
+ public DataSource getDataSource() {
+ return this.ds;
+ }
+
+ /**
+ * Execute an SQL SELECT query with a single replacement parameter. The
+ * caller is responsible for connection cleanup.
+ *
+ * @param conn The connection to execute the query in.
+ * @param sql The query to execute.
+ * @param param The replacement parameter.
+ * @param rsh The handler that converts the results into an object.
+ * @return The object returned by the handler.
+ * @throws SQLException
+ */
+ public Object query(
+ Connection conn,
+ String sql,
+ Object param,
+ ResultSetHandler rsh)
+ throws SQLException {
+
+ return this.query(conn, sql, new Object[] { param }, rsh);
+ }
+
+ /**
+ * Execute an SQL SELECT query with replacement parameters. The
+ * caller is responsible for connection cleanup.
+ *
+ * @param conn The connection to execute the query in.
+ * @param sql The query to execute.
+ * @param params The replacement parameters.
+ * @param rsh The handler that converts the results into an object.
+ * @return The object returned by the handler.
+ * @throws SQLException
+ */
+ public Object query(
+ Connection conn,
+ String sql,
+ Object[] params,
+ ResultSetHandler rsh)
+ throws SQLException {
+
+ PreparedStatement stmt = null;
+ ResultSet rs = null;
+ Object result = null;
+
+ try {
+ stmt = conn.prepareStatement(sql);
+ this.fillStatement(stmt, params);
+
+ rs = this.wrap(stmt.executeQuery());
+
+ result = rsh.handle(rs, params, null);
+
+ } catch (SQLException e) {
+ this.rethrow(e, sql, params);
+
+ } finally {
+ DbUtils.closeQuietly(rs);
+ DbUtils.closeQuietly(stmt);
+ }
+
+ return result;
+ }
+
+ /**
+ * Execute an SQL SELECT query without any replacement parameters. The
+ * caller is responsible for connection cleanup.
+ *
+ * @param conn The connection to execute the query in.
+ * @param sql The query to execute.
+ * @param rsh The handler that converts the results into an object.
+ * @return The object returned by the handler.
+ * @throws SQLException
+ */
+ public Object query(Connection conn, String sql, ResultSetHandler rsh)
+ throws SQLException {
+
+ return this.query(conn, sql, null, rsh);
+ }
+
+ /**
+ * Executes the given SELECT SQL with a single replacement parameter.
+ * The <code>Connection</code> is retrieved from the
+ * <code>DataSource</code> set in the constructor.
+ *
+ * @param sql The SQL statement to execute.
+ * @param rsh The handler used to create the result object from
+ * the <code>ResultSet</code>.
+ * @param param The replacement parameter.
+ * @return An object generated by the handler.
+ * @throws SQLException
+ */
+ public Object query(String sql, Object param, ResultSetHandler rsh)
+ throws SQLException {
+
+ return this.query(sql, new Object[] { param }, rsh);
+ }
+
+ /**
+ * Executes the given SELECT SQL query and returns a result object.
+ * The <code>Connection</code> is retrieved from the
+ * <code>DataSource</code> set in the constructor.
+ *
+ * @param sql The SQL statement to execute.
+ * @param params Initialize the PreparedStatement's IN parameters with this
+ * array.
+ * @param rsh The handler used to create the result object from
+ * the <code>ResultSet</code>.
+ * @return An object generated by the handler.
+ * @throws SQLException
+ */
+ public Object query(String sql, Object[] params, ResultSetHandler rsh)
+ throws SQLException {
+
+ Connection conn = this.ds.getConnection();
+
+ Object result = null;
+
+ try {
+ result = this.query(conn, sql, params, rsh);
+
+ } finally {
+ DbUtils.close(conn);
+ }
+
+ return result;
+ }
+
+ /**
+ * Executes the given SELECT SQL without any replacement parameters.
+ * The <code>Connection</code> is retrieved from the
+ * <code>DataSource</code> set in the constructor.
+ *
+ * @param sql The SQL statement to execute.
+ * @param rsh The handler used to create the result object from
+ * the <code>ResultSet</code>.
+ * @return An object generated by the handler.
+ * @throws SQLException
+ */
+ public Object query(String sql, ResultSetHandler rsh) throws SQLException {
+ return this.query(sql, null, rsh);
+ }
+
+ /**
+ * Throws a new exception with a more informative error message.
+ * @param cause The original exception that will be chained to the new
+ * exception when it's rethrown.
+ * @param sql The query that was executing when the exception happened.
+ * @param params The query replacement paramaters; <code>null</code> is a
+ * valid value to pass in.
+ * @throws SQLException
+ */
+ protected void rethrow(SQLException cause, String sql, Object[] params)
+ throws SQLException {
+
+ StringBuffer msg =
+ new StringBuffer(cause.getMessage() + " in query " + sql);
+ if (params != null) {
+ msg.append(Arrays.asList(params).toString());
+ }
+
+ SQLException newsqle = new SQLException(msg.toString());
+ newsqle.setNextException(cause);
+
+ throw newsqle;
+ }
+
+ /**
+ * Sets the <code>DataSource</code> this runner will use to get
+ * database connections from. This should be called after creating a
+ * runner with the default constructor if you intend to use the
+ * execute methods without passing in a <code>Connection</code>.
+ * @param dataSource The DataSource to use.
+ */
+ public void setDataSource(DataSource dataSource) {
+ this.ds = dataSource;
+ }
+
+ /**
+ * Execute an SQL INSERT, UPDATE, or DELETE query without replacement
+ * parameters.
+ *
+ * @param conn The connection to use to run the query.
+ * @param sql The SQL to execute.
+ * @return The number of rows updated.
+ * @throws SQLException
+ */
+ public int update(Connection conn, String sql) throws SQLException {
+ return this.update(conn, sql, null);
+ }
+
+ /**
+ * Execute an SQL INSERT, UPDATE, or DELETE query with a single replacement
+ * parameter.
+ *
+ * @param conn The connection to use to run the query.
+ * @param sql The SQL to execute.
+ * @param param The replacement parameter.
+ * @return The number of rows updated.
+ * @throws SQLException
+ */
+ public int update(Connection conn, String sql, Object param)
+ throws SQLException {
+
+ return this.update(conn, sql, new Object[] { param });
+ }
+
+ /**
+ * Execute an SQL INSERT, UPDATE, or DELETE query.
+ * @param conn The connection to use to run the query.
+ * @param sql The SQL to execute.
+ * @param params The query replacement parameters.
+ * @return The number of rows updated.
+ * @throws SQLException
+ */
+ public int update(Connection conn, String sql, Object[] params)
+ throws SQLException {
+
+ PreparedStatement stmt = conn.prepareStatement(sql);
+ this.fillStatement(stmt, params);
+
+ int rows = 0;
+
+ try {
+ rows = stmt.executeUpdate();
+
+ } catch (SQLException e) {
+ this.rethrow(e, sql, params);
+
+ } finally {
+ DbUtils.closeQuietly(stmt);
+ }
+
+ return rows;
+ }
+
+ /**
+ * Executes the given INSERT, UPDATE, or DELETE SQL statement without
+ * any replacement parameters. The statement is executed in it's own
+ * transaction that will be committed or rolled back depending on any
+ * SQLExceptions thrown. The <code>Connection</code> is retrieved from the
+ * <code>DataSource</code> set in the constructor.
+ *
+ * @param sql The SQL statement to execute.
+ * @throws SQLException
+ * @return The number of rows updated.
+ */
+ public int update(String sql) throws SQLException {
+ return this.update(sql, null);
+ }
+
+ /**
+ * Executes the given INSERT, UPDATE, or DELETE SQL statement with
+ * a single replacement parameter. The statement is executed in it's own
+ * transaction that will be committed or rolled back depending on any
+ * SQLExceptions thrown. The <code>Connection</code> is retrieved from the
+ * <code>DataSource</code> set in the constructor.
+ *
+ * @param sql The SQL statement to execute.
+ * @param param The replacement parameter.
+ * @throws SQLException
+ * @return The number of rows updated.
+ */
+ public int update(String sql, Object param) throws SQLException {
+ return this.update(sql, new Object[] { param });
+ }
+
+ /**
+ * Executes the given INSERT, UPDATE, or DELETE SQL statement. The
+ * statement is executed in it's own transaction that will be committed or
+ * rolled back depending on any SQLExceptions thrown. The
+ * <code>Connection</code> is retrieved from the <code>DataSource</code>
+ * set in the constructor.
+ *
+ * @param sql The SQL statement to execute.
+ * @param params Initializes the PreparedStatement's IN (ie. '?')
+ * parameters.
+ * @throws SQLException
+ * @return The number of rows updated.
+ */
+ public int update(String sql, Object[] params) throws SQLException {
+
+ Connection conn = this.ds.getConnection();
+
+ int rows = 0;
+
+ try {
+ conn.setAutoCommit(false); // single transaction.
+ rows = this.update(conn, sql, params);
+ conn.commit();
+
+ } catch (SQLException e) {
+ DbUtils.rollback(conn);
+ throw e;
+
+ } finally {
+ DbUtils.close(conn);
+ }
+
+ return rows;
+ }
+
+ /**
+ * Wrap the <code>ResultSet</code> in a decorator before processing it.
+ * This implementation returns the <code>ResultSet</code> it is given
+ * without any decoration.
+ *
+ * <p>
+ * Often, the implementation of this method can be done in an anonymous
+ * inner class like this:
+ * </p>
+ * <pre>
+ * QueryRunner run = new QueryRunner() {
+ * protected void wrap(ResultSet rs) {
+ * return StringTrimmedResultSet.wrap(rs);
+ * }
+ * };
+ * </pre>
+ *
+ * @param rs The <code>ResultSet</code> to decorate; never
+ * <code>null</code>.
+ * @return The <code>ResultSet</code> wrapped in some decorator.
+ */
+ protected ResultSet wrap(ResultSet rs) {
+ return rs;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]