dgraham 2003/10/28 16:49:56
Modified: dbutils/src/java/org/apache/commons/dbutils QueryRunner.java
Log:
Added a protected prepareStatement() method so
subclasses can override PreparedStatement initialization.
For example, they might want to call:
conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)
instead of the standard initialization.
Revision Changes Path
1.13 +25 -5
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.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- QueryRunner.java 24 Oct 2003 04:25:25 -0000 1.12
+++ QueryRunner.java 29 Oct 2003 00:49:56 -0000 1.13
@@ -139,6 +139,26 @@
}
/**
+ * Factory method that creates and initializes a
+ * <code>PreparedStatement</code> object for the given SQL.
+ * <code>QueryRunner</code> methods always call this method to prepare
+ * statements for them. Subclasses can override this method to provide
+ * special PreparedStatement configuration if needed. This implementation
+ * simply calls <code>conn.prepareStatement(sql)</code>.
+ *
+ * @param conn The <code>Connection</code> used to create the
+ * <code>PreparedStatement</code>
+ * @param sql The SQL statement to prepare.
+ * @return An initialized <code>PreparedStatement</code>.
+ * @throws SQLException
+ */
+ protected PreparedStatement prepareStatement(Connection conn, String sql)
+ throws SQLException {
+
+ return conn.prepareStatement(sql);
+ }
+
+ /**
* Execute an SQL SELECT query with a single replacement parameter. The
* caller is responsible for connection cleanup.
*
@@ -182,7 +202,7 @@
Object result = null;
try {
- stmt = conn.prepareStatement(sql);
+ stmt = this.prepareStatement(conn, sql);
this.fillStatement(stmt, params);
rs = this.wrap(stmt.executeQuery());
@@ -367,7 +387,7 @@
int rows = 0;
try {
- stmt = conn.prepareStatement(sql);
+ stmt = this.prepareStatement(conn, sql);
this.fillStatement(stmt, params);
rows = stmt.executeUpdate();
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]