KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jodd > db > LoggablePreparedStatement


1 // Copyright (c) 2003-2007, Jodd Team (jodd.sf.net). All Rights Reserved.
2
package jodd.db;
3
4 import java.sql.Connection JavaDoc;
5 import java.sql.PreparedStatement JavaDoc;
6 import java.sql.SQLException JavaDoc;
7 import java.sql.ParameterMetaData JavaDoc;
8 import java.sql.ResultSet JavaDoc;
9 import java.util.ArrayList JavaDoc;
10 import java.util.Date JavaDoc;
11 import java.util.StringTokenizer JavaDoc;
12 import java.net.URL JavaDoc;
13 import java.io.InputStream JavaDoc;
14
15 /**
16  * A <code>LoggablePreparedStatement</code> is a {@link PreparedStatement} with added logging capability.
17  * <p>
18  * In addition to the methods declared in <code>PreparedStatement</code>,
19  * <code>LoggablePreparedStatement</code> provides a method {@link #getQueryString} which can be used to get
20  * the query string in a format suitable for logging.
21  */

22 public class LoggablePreparedStatement implements PreparedStatement JavaDoc {
23
24     /**
25      * Used for storing parameter values needed for producing log.
26      */

27     private ArrayList JavaDoc parameterValues;
28
29     /**
30      * The query string with question marks as parameter placeholders.
31      */

32     private String JavaDoc sqlTemplate;
33
34     /**
35      * A statement created from a real database connection.
36      */

37     private PreparedStatement JavaDoc wrappedStatement;
38
39     /**
40     * Constructs a LoggablePreparedStatement.
41     *
42     * Creates {@link java.sql.PreparedStatement PreparedStatement} with the query string <code>sql</code> using
43     * the specified <code>conn</code> by calling {@link java.sql.Connection#prepareStatement(String)}.
44     * <p>
45     * Whenever a call is made to this <code>LoggablePreparedStatement</code> it is forwarded to the prepared statment created from
46     * <code>conn</code> after first saving relevant parameters for use in logging output.
47     *
48     * @param connection java.sql.Connection a JDBC-conn to be used for obtaining a "real statement"
49     * @param sql java.lang.String thw sql to exectute
50     * @exception SQLException if a <code>PreparedStatement</code> cannot be created using the supplied <code>conn</code> and <code>sql</code>
51     */

52     public LoggablePreparedStatement(Connection JavaDoc connection, String JavaDoc sql) throws SQLException JavaDoc {
53         wrappedStatement = connection.prepareStatement(sql);
54         sqlTemplate = sql;
55         parameterValues = new ArrayList JavaDoc();
56     }
57
58     public LoggablePreparedStatement(Connection JavaDoc connection, String JavaDoc sql, int resultType, int resultSetConcurrency) throws SQLException JavaDoc {
59         wrappedStatement = connection.prepareStatement(sql, resultType, resultSetConcurrency);
60         sqlTemplate = sql;
61         parameterValues = new ArrayList JavaDoc();
62     }
63
64     /**
65      * JDBC 2.0
66      *
67      * Adds a set of parameters to the batch.
68      *
69      * @exception SQLException if a database access error occurs
70      * @see java.sql.Statement#addBatch
71      */

72     public void addBatch() throws SQLException JavaDoc {
73         wrappedStatement.addBatch();
74     }
75     /**
76      * JDBC 2.0
77      *
78      * Adds a SQL command to the current batch of commmands for the statement.
79      * This method is optional.
80      *
81      * @param sql typically this is a static SQL INSERT or UPDATE statement
82      * @exception SQLException if a database access error occurs, or the
83      * driver does not support batch statements
84      */

85     public void addBatch(String JavaDoc sql) throws SQLException JavaDoc {
86         wrappedStatement.addBatch(sql);
87     }
88     /**
89      * Cancels this <code>Statement</code> object if both the DBMS and
90      * driver support aborting an SQL statement.
91      * This method can be used by one thread to cancel a statement that
92      * is being executed by another thread.
93      *
94      * @exception SQLException if a database access error occurs
95      */

96     public void cancel() throws SQLException JavaDoc {
97         wrappedStatement.cancel();
98     }
99     /**
100      * JDBC 2.0
101      *
102      * Makes the set of commands in the current batch empty.
103      * This method is optional.
104      *
105      * @exception SQLException if a database access error occurs or the
106      * driver does not support batch statements
107      */

108     public void clearBatch() throws SQLException JavaDoc {
109         wrappedStatement.clearBatch();
110     }
111     /**
112      * Clears the current parameter values immediately.
113      * <P>In general, parameter values remain in force for repeated use of a
114      * Statement. Setting a parameter value automatically clears its
115      * previous value. However, in some cases it is useful to immediately
116      * release the resources used by the current parameter values; this can
117      * be done by calling clearParameters.
118      *
119      * @exception SQLException if a database access error occurs
120      */

121     public void clearParameters() throws SQLException JavaDoc {
122         wrappedStatement.clearParameters();
123     }
124     /**
125      * Clears all the warnings reported on this <code>Statement</code>
126      * object. After a call to this method,
127      * the method <code>getWarnings</code> will return
128      * null until a new warning is reported for this Statement.
129      *
130      * @exception SQLException if a database access error occurs
131      */

132     public void clearWarnings() throws SQLException JavaDoc {
133         wrappedStatement.clearWarnings();
134     }
135     /**
136      * Releases this <code>Statement</code> object's database
137      * and JDBC resources immediately instead of waiting for
138      * this to happen when it is automatically closed.
139      * It is generally good practice to release resources as soon as
140      * you are finished with them to avoid tying up database
141      * resources.
142      * <P><B>Note:</B> A Statement is automatically closed when it is
143      * garbage collected. When a Statement is closed, its current
144      * ResultSet, if one exists, is also closed.
145      *
146      * @exception SQLException if a database access error occurs
147      */

148     public void close() throws SQLException JavaDoc {
149         wrappedStatement.close();
150     }
151     /**
152      * Executes any kind of SQL statement.
153      * Some prepared statements return multiple results; the execute
154      * method handles these complex statements as well as the simpler
155      * form of statements handled by executeQuery and executeUpdate.
156      *
157      * @exception SQLException if a database access error occurs
158      * @see java.sql.Statement#execute
159      */

160     public boolean execute() throws SQLException JavaDoc {
161         return wrappedStatement.execute();
162     }
163     /**
164      * Executes a SQL statement that may return multiple results.
165      * Under some (uncommon) situations a single SQL statement may return
166      * multiple result sets and/or update counts. Normally you can ignore
167      * this unless you are (1) executing a stored procedure that you know may
168      * return multiple results or (2) you are dynamically executing an
169      * unknown SQL string. The methods <code>execute</code>,
170      * <code>getMoreResults</code>, <code>getResultSet</code>,
171      * and <code>getUpdateCount</code> let you navigate through multiple results.
172      *
173      * The <code>execute</code> method executes a SQL statement and indicates the
174      * form of the first result. You can then use getResultSet or
175      * getUpdateCount to retrieve the result, and getMoreResults to
176      * move to any subsequent result(s).
177      *
178      * @param sql any SQL statement
179      * @return true if the next result is a ResultSet; false if it is
180      * an update count or there are no more results
181      * @exception SQLException if a database access error occurs
182      * @see #getResultSet
183      * @see #getUpdateCount
184      * @see #getMoreResults
185      */

186     public boolean execute(String JavaDoc sql) throws SQLException JavaDoc {
187         return wrappedStatement.execute(sql);
188     }
189     /**
190      * JDBC 2.0
191      *
192      * Submits a batch of commands to the database for execution.
193      * This method is optional.
194      *
195      * @return an array of update counts containing one element for each
196      * command in the batch. The array is ordered according
197      * to the order in which commands were inserted into the batch.
198      * @exception SQLException if a database access error occurs or the
199      * driver does not support batch statements
200      */

201     public int[] executeBatch() throws SQLException JavaDoc {
202         return wrappedStatement.executeBatch();
203     }
204     /**
205      * Executes the SQL query in this <code>PreparedStatement</code> object
206      * and returns the result set generated by the query.
207      *
208      * @return a ResultSet that contains the data produced by the
209      * query; never null
210      * @exception SQLException if a database access error occurs
211      */

212     public ResultSet JavaDoc executeQuery() throws SQLException JavaDoc {
213         return wrappedStatement.executeQuery();
214     }
215     /**
216      * Executes a SQL statement that returns a single ResultSet.
217      *
218      * @param sql typically this is a static SQL SELECT statement
219      * @return a ResultSet that contains the data produced by the
220      * query; never null
221      * @exception SQLException if a database access error occurs
222      */

223     public ResultSet JavaDoc executeQuery(String JavaDoc sql) throws SQLException JavaDoc {
224         return wrappedStatement.executeQuery(sql);
225     }
226     /**
227      * Executes the SQL INSERT, UPDATE or DELETE statement
228      * in this <code>PreparedStatement</code> object.
229      * In addition,
230      * SQL statements that return nothing, such as SQL DDL statements,
231      * can be executed.
232      *
233      * @return either the row count for INSERT, UPDATE or DELETE statements;
234      * or 0 for SQL statements that return nothing
235      * @exception SQLException if a database access error occurs
236      */

237     public int executeUpdate() throws SQLException JavaDoc {
238         return wrappedStatement.executeUpdate();
239     }
240     /**
241      * Executes an SQL INSERT, UPDATE or DELETE statement. In addition,
242      * SQL statements that return nothing, such as SQL DDL statements,
243      * can be executed.
244      *
245      * @param sql a SQL INSERT, UPDATE or DELETE statement or a SQL
246      * statement that returns nothing
247      * @return either the row count for INSERT, UPDATE or DELETE or 0
248      * for SQL statements that return nothing
249      * @exception SQLException if a database access error occurs
250      */

251     public int executeUpdate(String JavaDoc sql) throws SQLException JavaDoc {
252         return wrappedStatement.executeUpdate(sql);
253     }
254     /**
255      * JDBC 2.0
256      *
257      * Returns the <code>Connection</code> object
258      * that produced this <code>Statement</code> object.
259      * @return the conn that produced this statement
260      * @exception SQLException if a database access error occurs
261      */

262     public java.sql.Connection JavaDoc getConnection() throws SQLException JavaDoc {
263         return wrappedStatement.getConnection();
264     }
265     /**
266      * JDBC 2.0
267      *
268      * Retrieves the direction for fetching rows from
269      * database tables that is the default for result sets
270      * generated from this <code>Statement</code> object.
271      * If this <code>Statement</code> object has not set
272      * a fetch direction by calling the method <code>setFetchDirection</code>,
273      * the return value is implementation-specific.
274      *
275      * @return the default fetch direction for result sets generated
276      * from this <code>Statement</code> object
277      * @exception SQLException if a database access error occurs
278      */

279     public int getFetchDirection() throws SQLException JavaDoc {
280         return wrappedStatement.getFetchDirection();
281     }
282     /**
283      * JDBC 2.0
284      *
285      * Retrieves the number of result set rows that is the default
286      * fetch size for result sets
287      * generated from this <code>Statement</code> object.
288      * If this <code>Statement</code> object has not set
289      * a fetch size by calling the method <code>setFetchSize</code>,
290      * the return value is implementation-specific.
291      * @return the default fetch size for result sets generated
292      * from this <code>Statement</code> object
293      * @exception SQLException if a database access error occurs
294      */

295     public int getFetchSize() throws SQLException JavaDoc {
296         return wrappedStatement.getFetchSize();
297     }
298     /**
299      * Returns the maximum number of bytes allowed
300      * for any column value.
301      * This limit is the maximum number of bytes that can be
302      * returned for any column value.
303      * The limit applies only to BINARY,
304      * VARBINARY, LONGVARBINARY, CHAR, VARCHAR, and LONGVARCHAR
305      * columns. If the limit is exceeded, the excess data is silently
306      * discarded.
307      *
308      * @return the current max column size limit; zero means unlimited
309      * @exception SQLException if a database access error occurs
310      */

311     public int getMaxFieldSize() throws SQLException JavaDoc {
312         return wrappedStatement.getMaxFieldSize();
313     }
314     /**
315      * Retrieves the maximum number of rows that a
316      * ResultSet can contain. If the limit is exceeded, the excess
317      * rows are silently dropped.
318      *
319      * @return the current max row limit; zero means unlimited
320      * @exception SQLException if a database access error occurs
321      */

322     public int getMaxRows() throws SQLException JavaDoc {
323         return wrappedStatement.getMaxRows();
324     }
325     /**
326      * JDBC 2.0
327      *
328      * Gets the number, types and properties of a ResultSet's columns.
329      *
330      * @return the description of a ResultSet's columns
331      * @exception SQLException if a database access error occurs
332      */

333     public java.sql.ResultSetMetaData JavaDoc getMetaData() throws SQLException JavaDoc {
334         return wrappedStatement.getMetaData();
335     }
336     /**
337      * Moves to a Statement's next result. It returns true if
338      * this result is a ResultSet. This method also implicitly
339      * closes any current ResultSet obtained with getResultSet.
340      *
341      * There are no more results when (!getMoreResults() &&
342      * (getUpdateCount() == -1)
343      *
344      * @return true if the next result is a ResultSet; false if it is
345      * an update count or there are no more results
346      * @exception SQLException if a database access error occurs
347      * @see #execute
348      */

349     public boolean getMoreResults() throws SQLException JavaDoc {
350         return wrappedStatement.getMoreResults();
351     }
352     /**
353      * Retrieves the number of seconds the driver will
354      * wait for a Statement to execute. If the limit is exceeded, a
355      * SQLException is thrown.
356      *
357      * @return the current query timeout limit in seconds; zero means unlimited
358      * @exception SQLException if a database access error occurs
359      */

360     public int getQueryTimeout() throws SQLException JavaDoc {
361         return wrappedStatement.getQueryTimeout();
362     }
363     /**
364      * Returns the current result as a <code>ResultSet</code> object.
365      * This method should be called only once per result.
366      *
367      * @return the current result as a ResultSet; null if the result
368      * is an update count or there are no more results
369      * @exception SQLException if a database access error occurs
370      * @see #execute
371      */

372     public ResultSet JavaDoc getResultSet() throws SQLException JavaDoc {
373         return wrappedStatement.getResultSet();
374     }
375     /**
376      * JDBC 2.0
377      *
378      * Retrieves the result set concurrency.
379      */

380     public int getResultSetConcurrency() throws SQLException JavaDoc {
381         return wrappedStatement.getResultSetConcurrency();
382     }
383     /**
384      * JDBC 2.0
385      *
386      * Determine the result set type.
387      */

388     public int getResultSetType() throws SQLException JavaDoc {
389         return wrappedStatement.getResultSetType();
390     }
391     /**
392      * Returns the current result as an update count;
393      * if the result is a ResultSet or there are no more results, -1
394      * is returned.
395      * This method should be called only once per result.
396      *
397      * @return the current result as an update count; -1 if it is a
398      * ResultSet or there are no more results
399      * @exception SQLException if a database access error occurs
400      * @see #execute
401      */

402     public int getUpdateCount() throws SQLException JavaDoc {
403         return wrappedStatement.getUpdateCount();
404     }
405     /**
406      * Retrieves the first warning reported by calls on this Statement.
407      * Subsequent Statement warnings will be chained to this
408      * SQLWarning.
409      *
410      * <p>The warning chain is automatically cleared each time
411      * a statement is (re)executed.
412      *
413      * <P><B>Note:</B> If you are processing a ResultSet, any
414      * warnings associated with ResultSet reads will be chained on the
415      * ResultSet object.
416      *
417      * @return the first SQLWarning or null
418      * @exception SQLException if a database access error occurs
419      */

420     public java.sql.SQLWarning JavaDoc getWarnings() throws SQLException JavaDoc {
421         return wrappedStatement.getWarnings();
422     }
423     /**
424      * JDBC 2.0
425      *
426      * Sets an Array parameter.
427      *
428      * @param i the first parameter is 1, the second is 2, ...
429      * @param x an object representing an SQL array
430      * @exception SQLException if a database access error occurs
431      */

432     public void setArray(int i, java.sql.Array JavaDoc x) throws SQLException JavaDoc {
433         wrappedStatement.setArray(i, x);
434         saveQueryParamValue(i, x);
435
436     }
437     /**
438      * Sets the designated parameter to the given input stream, which will have
439      * the specified number of bytes.
440      * When a very large ASCII value is input to a LONGVARCHAR
441      * parameter, it may be more practical to send it via a
442      * InputStream. JDBC will read the data from the stream
443      * as needed, until it reaches end-of-file. The JDBC driver will
444      * do any necessary conversion from ASCII to the database char format.
445      *
446      * <P><B>Note:</B> This stream object can either be a standard
447      * Java stream object or your own subclass that implements the
448      * standard interface.
449      *
450      * @param parameterIndex the first parameter is 1, the second is 2, ...
451      * @param x the Java input stream that contains the ASCII parameter value
452      * @param length the number of bytes in the stream
453      * @exception SQLException if a database access error occurs
454      */

455     public void setAsciiStream(int parameterIndex, InputStream JavaDoc x, int length) throws SQLException JavaDoc {
456         wrappedStatement.setAsciiStream(parameterIndex, x, length);
457         saveQueryParamValue(parameterIndex, x);
458     }
459     /**
460      * Sets the designated parameter to a java.lang.BigDecimal value.
461      * The driver converts this to an SQL NUMERIC value when
462      * it sends it to the database.
463      *
464      * @param parameterIndex the first parameter is 1, the second is 2, ...
465      * @param x the parameter value
466      * @exception SQLException if a database access error occurs
467      */

468     public void setBigDecimal(int parameterIndex, java.math.BigDecimal JavaDoc x) throws SQLException JavaDoc {
469         wrappedStatement.setBigDecimal(parameterIndex, x);
470         saveQueryParamValue(parameterIndex, x);
471
472     }
473
474     /**
475      * Sets the designated parameter to the given input stream, which will have
476      * the specified number of bytes.
477      * When a very large binary value is input to a LONGVARBINARY
478      * parameter, it may be more practical to send it via a
479      * InputStream. JDBC will read the data from the stream
480      * as needed, until it reaches end-of-file.
481      *
482      * <P><B>Note:</B> This stream object can either be a standard
483      * Java stream object or your own subclass that implements the
484      * standard interface.
485      *
486      * @param parameterIndex the first parameter is 1, the second is 2, ...
487      * @param x the java input stream which contains the binary parameter value
488      * @param length the number of bytes in the stream
489      * @exception SQLException if a database access error occurs
490      */

491     public void setBinaryStream(int parameterIndex, InputStream JavaDoc x, int length) throws SQLException JavaDoc {
492         wrappedStatement.setBinaryStream(parameterIndex, x, length);
493         saveQueryParamValue(parameterIndex, x);
494
495     }
496     /**
497      * JDBC 2.0
498      *
499      * Sets a BLOB parameter.
500      *
501      * @param i the first parameter is 1, the second is 2, ...
502      * @param x an object representing a BLOB
503      * @exception SQLException if a database access error occurs
504      */

505     public void setBlob(int i, java.sql.Blob JavaDoc x) throws SQLException JavaDoc {
506         wrappedStatement.setBlob(i, x);
507         saveQueryParamValue(i, x);
508     }
509     /**
510      * Sets the designated parameter to a Java boolean value. The driver converts this
511      * to an SQL BIT value when it sends it to the database.
512      *
513      * @param parameterIndex the first parameter is 1, the second is 2, ...
514      * @param x the parameter value
515      * @exception SQLException if a database access error occurs
516      */

517     public void setBoolean(int parameterIndex, boolean x) throws SQLException JavaDoc {
518         wrappedStatement.setBoolean(parameterIndex, x);
519         saveQueryParamValue(parameterIndex, Boolean.valueOf(x));
520
521     }
522     /**
523      * Sets the designated parameter to a Java byte value. The driver converts this
524      * to an SQL TINYINT value when it sends it to the database.
525      *
526      * @param parameterIndex the first parameter is 1, the second is 2, ...
527      * @param x the parameter value
528      * @exception SQLException if a database access error occurs
529      */

530     public void setByte(int parameterIndex, byte x) throws SQLException JavaDoc {
531         wrappedStatement.setByte(parameterIndex, x);
532         saveQueryParamValue(parameterIndex, new Integer JavaDoc(x));
533     }
534     /**
535      * Sets the designated parameter to a Java array of bytes. The driver converts
536      * this to an SQL VARBINARY or LONGVARBINARY (depending on the
537      * argument's size relative to the driver's limits on VARBINARYs)
538      * when it sends it to the database.
539      *
540      * @param parameterIndex the first parameter is 1, the second is 2, ...
541      * @param x the parameter value
542      * @exception SQLException if a database access error occurs
543      */

544     public void setBytes(int parameterIndex, byte[] x) throws SQLException JavaDoc {
545         wrappedStatement.setBytes(parameterIndex, x);
546         saveQueryParamValue(parameterIndex, x);
547     }
548     /**
549      * JDBC 2.0
550      *
551      * Sets the designated parameter to the given <code>Reader</code>
552      * object, which is the given number of characters long.
553      * When a very large UNICODE value is input to a LONGVARCHAR
554      * parameter, it may be more practical to send it via a
555      * java.io.Reader. JDBC will read the data from the stream
556      * as needed, until it reaches end-of-file. The JDBC driver will
557      * do any necessary conversion from UNICODE to the database char format.
558      *
559      * <P><B>Note:</B> This stream object can either be a standard
560      * Java stream object or your own subclass that implements the
561      * standard interface.
562      *
563      * @param parameterIndex the first parameter is 1, the second is 2, ...
564      * @param reader the java reader which contains the UNICODE data
565      * @param length the number of characters in the stream
566      * @exception SQLException if a database access error occurs
567      */

568     public void setCharacterStream(int parameterIndex, java.io.Reader JavaDoc reader, int length) throws SQLException JavaDoc {
569         wrappedStatement.setCharacterStream(parameterIndex, reader, length);
570         saveQueryParamValue(parameterIndex, reader);
571
572     }
573     /**
574      * JDBC 2.0
575      *
576      * Sets a CLOB parameter.
577      *
578      * @param i the first parameter is 1, the second is 2, ...
579      * @param x an object representing a CLOB
580      * @exception SQLException if a database access error occurs
581      */

582     public void setClob(int i, java.sql.Clob JavaDoc x) throws SQLException JavaDoc {
583         wrappedStatement.setClob(i, x);
584         saveQueryParamValue(i, x);
585
586     }
587     /**
588      * Defines the SQL cursor name that will be used by
589      * subsequent Statement <code>execute</code> methods. This name can then be
590      * used in SQL positioned update/delete statements to identify the
591      * current row in the ResultSet generated by this statement. If
592      * the database doesn't support positioned update/delete, this
593      * method is a noop. To insure that a cursor has the proper isolation
594      * level to support updates, the cursor's SELECT statement should be
595      * of the form 'select for update ...'. If the 'for update' phrase is
596      * omitted, positioned updates may fail.
597      *
598      * <P><B>Note:</B> By definition, positioned update/delete
599      * execution must be done by a different Statement than the one
600      * which generated the ResultSet being used for positioning. Also,
601      * cursor names must be unique within a conn.
602      *
603      * @param name the new cursor name, which must be unique within
604      * a conn
605      * @exception SQLException if a database access error occurs
606      */

607     public void setCursorName(String JavaDoc name) throws SQLException JavaDoc {
608         wrappedStatement.setCursorName(name);
609
610     }
611     /**
612      * Sets the designated parameter to a java.sql.Date value. The driver converts this
613      * to an SQL DATE value when it sends it to the database.
614      *
615      * @param parameterIndex the first parameter is 1, the second is 2, ...
616      * @param x the parameter value
617      * @exception SQLException if a database access error occurs
618      */

619     public void setDate(int parameterIndex, java.sql.Date JavaDoc x) throws SQLException JavaDoc {
620         wrappedStatement.setDate(parameterIndex, x);
621         saveQueryParamValue(parameterIndex, x);
622     }
623
624     /**
625      * JDBC 2.0
626      *
627      * Sets the designated parameter to a java.sql.Date value,
628      * using the given <code>Calendar</code> object. The driver uses
629      * the <code>Calendar</code> object to construct an SQL DATE,
630      * which the driver then sends to the database. With a
631      * a <code>Calendar</code> object, the driver can calculate the date
632      * taking into account a custom timezone and locale. If no
633      * <code>Calendar</code> object is specified, the driver uses the default
634      * timezone and locale.
635      *
636      * @param parameterIndex the first parameter is 1, the second is 2, ...
637      * @param x the parameter value
638      * @param cal the <code>Calendar</code> object the driver will use
639      * to construct the date
640      * @exception SQLException if a database access error occurs
641      */

642     public void setDate(int parameterIndex, java.sql.Date JavaDoc x, java.util.Calendar JavaDoc cal) throws SQLException JavaDoc {
643         wrappedStatement.setDate(parameterIndex, x, cal);
644         saveQueryParamValue(parameterIndex, x);
645     }
646     /**
647      * Sets the designated parameter to a Java double value. The driver converts this
648      * to an SQL DOUBLE value when it sends it to the database.
649      *
650      * @param parameterIndex the first parameter is 1, the second is 2, ...
651      * @param x the parameter value
652      * @exception SQLException if a database access error occurs
653      */

654     public void setDouble(int parameterIndex, double x) throws SQLException JavaDoc {
655         wrappedStatement.setDouble(parameterIndex, x);
656         saveQueryParamValue(parameterIndex, new Double JavaDoc(x));
657     }
658     /**
659      * Sets escape processing on or off.
660      * If escape scanning is on (the default), the driver will do
661      * escape substitution before sending the SQL to the database.
662      *
663      * Note: Since prepared statements have usually been parsed prior
664      * to making this call, disabling escape processing for prepared
665      * statements will have no effect.
666      *
667      * @param enable true to enable; false to disable
668      * @exception SQLException if a database access error occurs
669      */

670     public void setEscapeProcessing(boolean enable) throws SQLException JavaDoc {
671         wrappedStatement.setEscapeProcessing(enable);
672
673     }
674     /**
675      * JDBC 2.0
676      *
677      * Gives the driver a hint as to the direction in which
678      * the rows in a result set
679      * will be processed. The hint applies only to result sets created
680      * using this Statement object. The default value is
681      * ResultSet.FETCH_FORWARD.
682      * <p>Note that this method sets the default fetch direction for
683      * result sets generated by this <code>Statement</code> object.
684      * Each result set has its own methods for getting and setting
685      * its own fetch direction.
686      * @param direction the initial direction for processing rows
687      * @exception SQLException if a database access error occurs
688      * or the given direction
689      * is not one of ResultSet.FETCH_FORWARD, ResultSet.FETCH_REVERSE, or
690      * ResultSet.FETCH_UNKNOWN
691      */

692     public void setFetchDirection(int direction) throws SQLException JavaDoc {
693         wrappedStatement.setFetchDirection(direction);
694     }
695     /**
696      * JDBC 2.0
697      *
698      * Gives the JDBC driver a hint as to the number of rows that should
699      * be fetched from the database when more rows are needed. The number
700      * of rows specified affects only result sets created using this
701      * statement. If the value specified is zero, then the hint is ignored.
702      * The default value is zero.
703      *
704      * @param rows the number of rows to fetch
705      * @exception SQLException if a database access error occurs, or the
706      * condition 0 <= rows <= this.getMaxRows() is not satisfied.
707      */

708     public void setFetchSize(int rows) throws SQLException JavaDoc {
709         wrappedStatement.setFetchSize(rows);
710     }
711     /**
712      * Sets the designated parameter to a Java float value. The driver converts this
713      * to an SQL FLOAT value when it sends it to the database.
714      *
715      * @param parameterIndex the first parameter is 1, the second is 2, ...
716      * @param x the parameter value
717      * @exception SQLException if a database access error occurs
718      */

719     public void setFloat(int parameterIndex, float x) throws SQLException JavaDoc {
720         wrappedStatement.setFloat(parameterIndex, x);
721         saveQueryParamValue(parameterIndex, new Float JavaDoc(x));
722
723     }
724     /**
725      * Sets the designated parameter to a Java int value. The driver converts this
726      * to an SQL INTEGER value when it sends it to the database.
727      *
728      * @param parameterIndex the first parameter is 1, the second is 2, ...
729      * @param x the parameter value
730      * @exception SQLException if a database access error occurs
731      */

732     public void setInt(int parameterIndex, int x) throws SQLException JavaDoc {
733         wrappedStatement.setInt(parameterIndex, x);
734         saveQueryParamValue(parameterIndex, new Integer JavaDoc(x));
735     }
736     /**
737      * Sets the designated parameter to a Java long value. The driver converts this
738      * to an SQL BIGINT value when it sends it to the database.
739      *
740      * @param parameterIndex the first parameter is 1, the second is 2, ...
741      * @param x the parameter value
742      * @exception SQLException if a database access error occurs
743      */

744     public void setLong(int parameterIndex, long x) throws SQLException JavaDoc {
745         wrappedStatement.setLong(parameterIndex, x);
746         saveQueryParamValue(parameterIndex, new Long JavaDoc(x));
747
748     }
749     /**
750      * Sets the limit for the maximum number of bytes in a column to
751      * the given number of bytes. This is the maximum number of bytes
752      * that can be returned for any column value. This limit applies
753      * only to BINARY, VARBINARY, LONGVARBINARY, CHAR, VARCHAR, and
754      * LONGVARCHAR fields. If the limit is exceeded, the excess data
755      * is silently discarded. For maximum portability, use values
756      * greater than 256.
757      *
758      * @param max the new max column size limit; zero means unlimited
759      * @exception SQLException if a database access error occurs
760      */

761     public void setMaxFieldSize(int max) throws SQLException JavaDoc {
762         wrappedStatement.setMaxFieldSize(max);
763
764     }
765     /**
766      * Sets the limit for the maximum number of rows that any
767      * ResultSet can contain to the given number.
768      * If the limit is exceeded, the excess
769      * rows are silently dropped.
770      *
771      * @param max the new max rows limit; zero means unlimited
772      * @exception SQLException if a database access error occurs
773      */

774     public void setMaxRows(int max) throws SQLException JavaDoc {
775         wrappedStatement.setMaxRows(max);
776     }
777     /**
778      * Sets the designated parameter to SQL NULL.
779      *
780      * <P><B>Note:</B> You must specify the parameter's SQL type.
781      *
782      * @param parameterIndex the first parameter is 1, the second is 2, ...
783      * @param sqlType the SQL type code defined in java.sql.Types
784      * @exception SQLException if a database access error occurs
785      */

786     public void setNull(int parameterIndex, int sqlType) throws SQLException JavaDoc {
787         wrappedStatement.setNull(parameterIndex, sqlType);
788         saveQueryParamValue(parameterIndex, null);
789     }
790     /**
791      * JDBC 2.0
792      *
793      * Sets the designated parameter to SQL NULL. This version of setNull should
794      * be used for user-named types and REF type parameters. Examples
795      * of user-named types include: STRUCT, DISTINCT, JAVA_OBJECT, and
796      * named array types.
797      *
798      * <P><B>Note:</B> To be portable, applications must give the
799      * SQL type code and the fully-qualified SQL type name when specifying
800      * a NULL user-defined or REF parameter. In the case of a user-named type
801      * the name is the type name of the parameter itself. For a REF
802      * parameter the name is the type name of the referenced type. If
803      * a JDBC driver does not need the type code or type name information,
804      * it may ignore it.
805      *
806      * Although it is intended for user-named and Ref parameters,
807      * this method may be used to set a null parameter of any JDBC type.
808      * If the parameter does not have a user-named or REF type, the given
809      * typeName is ignored.
810      *
811      *
812      * @param parameterIndex the first parameter is 1, the second is 2, ...
813      * @param sqlType a value from java.sql.Types
814      * @param typeName the fully-qualified name of an SQL user-named type,
815      * ignored if the parameter is not a user-named type or REF
816      * @exception SQLException if a database access error occurs
817      */

818     public void setNull(int parameterIndex, int sqlType, String JavaDoc typeName) throws SQLException JavaDoc {
819         wrappedStatement.setNull(parameterIndex, sqlType, typeName);
820         saveQueryParamValue(parameterIndex, null);
821
822     }
823     /**
824      * <p>Sets the value of a parameter using an object; use the
825      * java.lang equivalent objects for integral values.
826      *
827      * <p>The JDBC specification specifies a standard mapping from
828      * Java Object types to SQL types. The given argument java object
829      * will be converted to the corresponding SQL type before being
830      * sent to the database.
831      *
832      * <p>Note that this method may be used to pass datatabase-
833      * specific abstract data types, by using a Driver-specific Java
834      * type.
835      *
836      * If the object is of a class implementing SQLData,
837      * the JDBC driver should call its method <code>writeSQL</code> to write it
838      * to the SQL data stream.
839      * If, on the other hand, the object is of a class implementing
840      * Ref, Blob, Clob, Struct,
841      * or Array, then the driver should pass it to the database as a value of the
842      * corresponding SQL type.
843      *
844      * This method throws an exception if there is an ambiguity, for example, if the
845      * object is of a class implementing more than one of those interfaces.
846      *
847      * @param parameterIndex the first parameter is 1, the second is 2, ...
848      * @param x the object containing the input parameter value
849      * @exception SQLException if a database access error occurs
850      */

851     public void setObject(int parameterIndex, Object JavaDoc x) throws SQLException JavaDoc {
852         wrappedStatement.setObject(parameterIndex, x);
853         saveQueryParamValue(parameterIndex, x);
854     }
855     /**
856          * Sets the value of the designated parameter with the given object.
857          * This method is like setObject above, except that it assumes a scale of zero.
858          *
859          * @param parameterIndex the first parameter is 1, the second is 2, ...
860          * @param x the object containing the input parameter value
861          * @param targetSqlType the SQL type (as defined in java.sql.Types) to be
862          * sent to the database
863          * @exception SQLException if a database access error occurs
864          */

865     public void setObject(int parameterIndex, Object JavaDoc x, int targetSqlType) throws SQLException JavaDoc {
866         wrappedStatement.setObject(parameterIndex, x, targetSqlType);
867         saveQueryParamValue(parameterIndex, x);
868     }
869     /**
870      * <p>Sets the value of a parameter using an object. The second
871      * argument must be an object type; for integral values, the
872      * java.lang equivalent objects should be used.
873      *
874      * <p>The given Java object will be converted to the targetSqlType
875      * before being sent to the database.
876      *
877      * If the object has a custom mapping (is of a class implementing SQLData),
878      * the JDBC driver should call its method <code>writeSQL</code> to write it
879      * to the SQL data stream.
880      * If, on the other hand, the object is of a class implementing
881      * Ref, Blob, Clob, Struct,
882      * or Array, the driver should pass it to the database as a value of the
883      * corresponding SQL type.
884      *
885      * <p>Note that this method may be used to pass datatabase-
886      * specific abstract data types.
887      *
888      * @param parameterIndex the first parameter is 1, the second is 2, ...
889      * @param x the object containing the input parameter value
890      * @param targetSqlType the SQL type (as defined in java.sql.Types) to be
891      * sent to the database. The scale argument may further qualify this type.
892      * @param scale for java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types,
893      * this is the number of digits after the decimal point. For all other
894      * types, this value will be ignored.
895      * @exception SQLException if a database access error occurs
896      * @see java.sql.Types
897      */

898     public void setObject(int parameterIndex, Object JavaDoc x, int targetSqlType, int scale) throws SQLException JavaDoc {
899         wrappedStatement.setObject(parameterIndex, x, targetSqlType, scale);
900         saveQueryParamValue(parameterIndex, x);
901     }
902     /**
903      * Sets the number of seconds the driver will
904      * wait for a Statement to execute to the given number of seconds.
905      * If the limit is exceeded, a SQLException is thrown.
906      *
907      * @param seconds the new query timeout limit in seconds; zero means
908      * unlimited
909      * @exception SQLException if a database access error occurs
910      */

911     public void setQueryTimeout(int seconds) throws SQLException JavaDoc {
912         wrappedStatement.setQueryTimeout(seconds);
913     }
914     /**
915      * JDBC 2.0
916      *
917      * Sets a REF(&lt;structured-type&gt;) parameter.
918      *
919      * @param i the first parameter is 1, the second is 2, ...
920      * @param x an object representing data of an SQL REF Type
921      * @exception SQLException if a database access error occurs
922      */

923     public void setRef(int i, java.sql.Ref JavaDoc x) throws SQLException JavaDoc {
924         wrappedStatement.setRef(i, x);
925         saveQueryParamValue(i, x);
926
927     }
928     /**
929      * Sets the designated parameter to a Java short value. The driver converts this
930      * to an SQL SMALLINT value when it sends it to the database.
931      *
932      * @param parameterIndex the first parameter is 1, the second is 2, ...
933      * @param x the parameter value
934      * @exception SQLException if a database access error occurs
935      */

936     public void setShort(int parameterIndex, short x) throws SQLException JavaDoc {
937         wrappedStatement.setShort(parameterIndex, x);
938         saveQueryParamValue(parameterIndex, new Integer JavaDoc(x));
939     }
940     /**
941      * Sets the designated parameter to a Java String value. The driver converts this
942      * to an SQL VARCHAR or LONGVARCHAR value (depending on the argument's
943      * size relative to the driver's limits on VARCHARs) when it sends
944      * it to the database.
945      *
946      * @param parameterIndex the first parameter is 1, the second is 2, ...
947      * @param x the parameter value
948      * @exception SQLException if a database access error occurs
949      */

950     public void setString(int parameterIndex, String JavaDoc x) throws SQLException JavaDoc {
951
952         wrappedStatement.setString(parameterIndex, x);
953         saveQueryParamValue(parameterIndex, x);
954     }
955     /**
956      * Sets the designated parameter to a java.sql.Time value. The driver converts this
957      * to an SQL TIME value when it sends it to the database.
958      *
959      * @param parameterIndex the first parameter is 1, the second is 2, ...
960      * @param x the parameter value
961      * @exception SQLException if a database access error occurs
962      */

963     public void setTime(int parameterIndex, java.sql.Time JavaDoc x) throws SQLException JavaDoc {
964         wrappedStatement.setTime(parameterIndex, x);
965         saveQueryParamValue(parameterIndex, x);
966     }
967     /**
968      * JDBC 2.0
969      *
970      * Sets the designated parameter to a java.sql.Time value,
971      * using the given <code>Calendar</code> object. The driver uses
972      * the <code>Calendar</code> object to construct an SQL TIME,
973      * which the driver then sends to the database. With a
974      * a <code>Calendar</code> object, the driver can calculate the time
975      * taking into account a custom timezone and locale. If no
976      * <code>Calendar</code> object is specified, the driver uses the default
977      * timezone and locale.
978      *
979      * @param parameterIndex the first parameter is 1, the second is 2, ...
980      * @param x the parameter value
981      * @param cal the <code>Calendar</code> object the driver will use
982      * to construct the time
983      * @exception SQLException if a database access error occurs
984      */

985     public void setTime(int parameterIndex, java.sql.Time JavaDoc x, java.util.Calendar JavaDoc cal) throws SQLException JavaDoc {
986         wrappedStatement.setTime(parameterIndex, x, cal);
987         saveQueryParamValue(parameterIndex, x);
988
989     }
990     /**
991      * Sets the designated parameter to a java.sql.Timestamp value. The driver
992      * converts this to an SQL TIMESTAMP value when it sends it to the
993      * database.
994      *
995      * @param parameterIndex the first parameter is 1, the second is 2, ...
996      * @param x the parameter value
997      * @exception SQLException if a database access error occurs
998      */

999     public void setTimestamp(int parameterIndex, java.sql.Timestamp JavaDoc x) throws SQLException JavaDoc {
1000        wrappedStatement.setTimestamp(parameterIndex, x);
1001        saveQueryParamValue(parameterIndex, x);
1002    }
1003    /**
1004     * JDBC 2.0
1005     *
1006     * Sets the designated parameter to a java.sql.Timestamp value,
1007     * using the given <code>Calendar</code> object. The driver uses
1008     * the <code>Calendar</code> object to construct an SQL TIMESTAMP,
1009     * which the driver then sends to the database. With a
1010     * a <code>Calendar</code> object, the driver can calculate the timestamp
1011     * taking into account a custom timezone and locale. If no
1012     * <code>Calendar</code> object is specified, the driver uses the default
1013     * timezone and locale.
1014     *
1015     * @param parameterIndex the first parameter is 1, the second is 2, ...
1016     * @param x the parameter value
1017     * @param cal the <code>Calendar</code> object the driver will use
1018     * to construct the timestamp
1019     * @exception SQLException if a database access error occurs
1020     */

1021    public void setTimestamp(int parameterIndex, java.sql.Timestamp JavaDoc x, java.util.Calendar JavaDoc cal) throws SQLException JavaDoc {
1022        wrappedStatement.setTimestamp(parameterIndex, x, cal);
1023        saveQueryParamValue(parameterIndex, x);
1024    }
1025    /**
1026     * Sets the designated parameter to the given input stream, which will have
1027     * the specified number of bytes.
1028     * When a very large UNICODE value is input to a LONGVARCHAR
1029     * parameter, it may be more practical to send it via a
1030     * InputStream. JDBC will read the data from the stream
1031     * as needed, until it reaches end-of-file. The JDBC driver will
1032     * do any necessary conversion from UNICODE to the database char format.
1033     * The byte format of the Unicode stream must be Java UTF-8, as
1034     * defined in the Java Virtual Machine Specification.
1035     *
1036     * <P><B>Note:</B> This stream object can either be a standard
1037     * Java stream object or your own subclass that implements the
1038     * standard interface.
1039     *
1040     * @param parameterIndex the first parameter is 1, the second is 2, ...
1041     * @param x the java input stream which contains the
1042     * UNICODE parameter value
1043     * @param length the number of bytes in the stream
1044     * @exception SQLException if a database access error occurs
1045     * @deprecated
1046     */

1047    public void setUnicodeStream(int parameterIndex, InputStream JavaDoc x, int length) throws SQLException JavaDoc {
1048        //noinspection deprecation
1049
wrappedStatement.setUnicodeStream(parameterIndex, x, length);
1050        saveQueryParamValue(parameterIndex, x);
1051    }
1052
1053    // ---------------------------------------------------------------- JDBC new
1054

1055    /**
1056     * Sets the designated parameter to the given <code>java.net.URL</code> value.
1057     * The driver converts this to an SQL <code>DATALINK</code> value
1058     * when it sends it to the database.
1059     *
1060     * @param parameterIndex the first parameter is 1, the second is 2, ...
1061     * @param x the <code>java.net.URL</code> object to be set
1062     * @throws java.sql.SQLException if a database access error occurs
1063     * @since 1.4
1064     */

1065    public void setURL(int parameterIndex, URL JavaDoc x) throws SQLException JavaDoc {
1066        wrappedStatement.setURL(parameterIndex, x);
1067        saveQueryParamValue(parameterIndex, x);
1068    }
1069
1070    /**
1071     * Retrieves the number, types and properties of this
1072     * <code>PreparedStatement</code> object's parameters.
1073     *
1074     * @return a <code>ParameterMetaData</code> object that contains information
1075     * about the number, types and properties of this
1076     * <code>PreparedStatement</code> object's parameters
1077     * @throws java.sql.SQLException if a database access error occurs
1078     * @see java.sql.ParameterMetaData
1079     * @since 1.4
1080     */

1081    public ParameterMetaData JavaDoc getParameterMetaData() throws SQLException JavaDoc {
1082        return wrappedStatement.getParameterMetaData();
1083    }
1084
1085    /**
1086     * Retrieves the result set holdability for <code>ResultSet</code> objects
1087     * generated by this <code>Statement</code> object.
1088     *
1089     * @return either <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
1090     * <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
1091     * @throws java.sql.SQLException if a database access error occurs
1092     * @since 1.4
1093     */

1094    public int getResultSetHoldability() throws SQLException JavaDoc {
1095        return wrappedStatement.getResultSetHoldability();
1096    }
1097
1098    /**
1099     * Moves to this <code>Statement</code> object's next result, deals with
1100     * any current <code>ResultSet</code> object(s) according to the instructions
1101     * specified by the given flag, and returns
1102     * <code>true</code> if the next result is a <code>ResultSet</code> object.
1103     * <p>
1104     * There are no more results when the following is true:
1105     * <PRE>
1106     * // stmt is a Statement object
1107     * ((stmt.getMoreResults() == false) && (stmt.getUpdateCount() == -1))
1108     * </PRE>
1109     *
1110     * @param current one of the following <code>Statement</code>
1111     * constants indicating what should happen to current
1112     * <code>ResultSet</code> objects obtained using the method
1113     * <code>getResultSet</code>:
1114     * <code>Statement.CLOSE_CURRENT_RESULT</code>,
1115     * <code>Statement.KEEP_CURRENT_RESULT</code>, or
1116     * <code>Statement.CLOSE_ALL_RESULTS</code>
1117     * @return <code>true</code> if the next result is a <code>ResultSet</code>
1118     * object; <code>false</code> if it is an update count or there are no
1119     * more results
1120     * @throws java.sql.SQLException if a database access error occurs or the argument
1121     * supplied is not one of the following:
1122     * <code>Statement.CLOSE_CURRENT_RESULT</code>,
1123     * <code>Statement.KEEP_CURRENT_RESULT</code>, or
1124     * <code>Statement.CLOSE_ALL_RESULTS</code>
1125     * @see #execute
1126     * @since 1.4
1127     */

1128    public boolean getMoreResults(int current) throws SQLException JavaDoc {
1129        return wrappedStatement.getMoreResults(current);
1130    }
1131
1132    /**
1133     * Retrieves any auto-generated keys created as a result of executing this
1134     * <code>Statement</code> object. If this <code>Statement</code> object did
1135     * not generate any keys, an empty <code>ResultSet</code>
1136     * object is returned.
1137     *
1138     * @return a <code>ResultSet</code> object containing the auto-generated key(s)
1139     * generated by the execution of this <code>Statement</code> object
1140     * @throws java.sql.SQLException if a database access error occurs
1141     * @since 1.4
1142     */

1143    public ResultSet JavaDoc getGeneratedKeys() throws SQLException JavaDoc {
1144        return wrappedStatement.getGeneratedKeys();
1145    }
1146
1147    /**
1148     * Executes the given SQL statement and signals the driver with the
1149     * given flag about whether the
1150     * auto-generated keys produced by this <code>Statement</code> object
1151     * should be made available for retrieval.
1152     *
1153     * @param sql must be an SQL <code>INSERT</code>, <code>UPDATE</code> or
1154     * <code>DELETE</code> statement or an SQL statement that
1155     * returns nothing
1156     * @param autoGeneratedKeys a flag indicating whether auto-generated keys
1157     * should be made available for retrieval;
1158     * one of the following constants:
1159     * <code>Statement.RETURN_GENERATED_KEYS</code>
1160     * <code>Statement.NO_GENERATED_KEYS</code>
1161     * @return either the row count for <code>INSERT</code>, <code>UPDATE</code>
1162     * or <code>DELETE</code> statements, or <code>0</code> for SQL
1163     * statements that return nothing
1164     * @throws java.sql.SQLException if a database access error occurs, the given
1165     * SQL statement returns a <code>ResultSet</code> object, or
1166     * the given constant is not one of those allowed
1167     * @since 1.4
1168     */

1169    public int executeUpdate(String JavaDoc sql, int autoGeneratedKeys) throws SQLException JavaDoc {
1170        return wrappedStatement.executeUpdate(sql, autoGeneratedKeys);
1171    }
1172
1173    /**
1174     * Executes the given SQL statement, which may return multiple results,
1175     * and signals the driver that any
1176     * auto-generated keys should be made available
1177     * for retrieval. The driver will ignore this signal if the SQL statement
1178     * is not an <code>INSERT</code> statement.
1179     * <p>
1180     * In some (uncommon) situations, a single SQL statement may return
1181     * multiple result sets and/or update counts. Normally you can ignore
1182     * this unless you are (1) executing a stored procedure that you know may
1183     * return multiple results or (2) you are dynamically executing an
1184     * unknown SQL string.
1185     * <p>
1186     * The <code>execute</code> method executes an SQL statement and indicates the
1187     * form of the first result. You must then use the methods
1188     * <code>getResultSet</code> or <code>getUpdateCount</code>
1189     * to retrieve the result, and <code>getMoreResults</code> to
1190     * move to any subsequent result(s).
1191     *
1192     * @param sql any SQL statement
1193     * @param autoGeneratedKeys a constant indicating whether auto-generated
1194     * keys should be made available for retrieval using the method
1195     * <code>getGeneratedKeys</code>; one of the following constants:
1196     * <code>Statement.RETURN_GENERATED_KEYS</code> or
1197     * <code>Statement.NO_GENERATED_KEYS</code>
1198     * @return <code>true</code> if the first result is a <code>ResultSet</code>
1199     * object; <code>false</code> if it is an update count or there are
1200     * no results
1201     * @throws java.sql.SQLException if a database access error occurs or the second
1202     * parameter supplied to this method is not
1203     * <code>Statement.RETURN_GENERATED_KEYS</code> or
1204     * <code>Statement.NO_GENERATED_KEYS</code>.
1205     * @see #getResultSet
1206     * @see #getUpdateCount
1207     * @see #getMoreResults
1208     * @see #getGeneratedKeys
1209     * @since 1.4
1210     */

1211    public boolean execute(String JavaDoc sql, int autoGeneratedKeys) throws SQLException JavaDoc {
1212        return wrappedStatement.execute(sql, autoGeneratedKeys);
1213    }
1214
1215    /**
1216     * Executes the given SQL statement and signals the driver that the
1217     * auto-generated keys indicated in the given array should be made available
1218     * for retrieval. The driver will ignore the array if the SQL statement
1219     * is not an <code>INSERT</code> statement.
1220     *
1221     * @param sql an SQL <code>INSERT</code>, <code>UPDATE</code> or
1222     * <code>DELETE</code> statement or an SQL statement that returns nothing,
1223     * such as an SQL DDL statement
1224     * @param columnIndexes an array of column indexes indicating the columns
1225     * that should be returned from the inserted row
1226     * @return either the row count for <code>INSERT</code>, <code>UPDATE</code>,
1227     * or <code>DELETE</code> statements, or 0 for SQL statements
1228     * that return nothing
1229     * @throws java.sql.SQLException if a database access error occurs, the SQL
1230     * statement returns a <code>ResultSet</code> object, or the
1231     * second argument supplied to this method is not an <code>int</code> array
1232     * whose elements are valid column indexes
1233     * @since 1.4
1234     */

1235    public int executeUpdate(String JavaDoc sql, int columnIndexes[]) throws SQLException JavaDoc {
1236        return wrappedStatement.executeUpdate(sql, columnIndexes);
1237    }
1238
1239    /**
1240     * Executes the given SQL statement, which may return multiple results,
1241     * and signals the driver that the
1242     * auto-generated keys indicated in the given array should be made available
1243     * for retrieval. This array contains the indexes of the columns in the
1244     * target table that contain the auto-generated keys that should be made
1245     * available. The driver will ignore the array if the given SQL statement
1246     * is not an <code>INSERT</code> statement.
1247     * <p>
1248     * Under some (uncommon) situations, a single SQL statement may return
1249     * multiple result sets and/or update counts. Normally you can ignore
1250     * this unless you are (1) executing a stored procedure that you know may
1251     * return multiple results or (2) you are dynamically executing an
1252     * unknown SQL string.
1253     * <p>
1254     * The <code>execute</code> method executes an SQL statement and indicates the
1255     * form of the first result. You must then use the methods
1256     * <code>getResultSet</code> or <code>getUpdateCount</code>
1257     * to retrieve the result, and <code>getMoreResults</code> to
1258     * move to any subsequent result(s).
1259     *
1260     * @param sql any SQL statement
1261     * @param columnIndexes an array of the indexes of the columns in the
1262     * inserted row that should be made available for retrieval by a
1263     * call to the method <code>getGeneratedKeys</code>
1264     * @return <code>true</code> if the first result is a <code>ResultSet</code>
1265     * object; <code>false</code> if it is an update count or there
1266     * are no results
1267     * @throws java.sql.SQLException if a database access error occurs or the
1268     * elements in the <code>int</code> array passed to this method
1269     * are not valid column indexes
1270     * @see #getResultSet
1271     * @see #getUpdateCount
1272     * @see #getMoreResults
1273     * @since 1.4
1274     */

1275    public boolean execute(String JavaDoc sql, int columnIndexes[]) throws SQLException JavaDoc {
1276        return wrappedStatement.execute(sql, columnIndexes);
1277    }
1278
1279    /**
1280     * Executes the given SQL statement and signals the driver that the
1281     * auto-generated keys indicated in the given array should be made available
1282     * for retrieval. The driver will ignore the array if the SQL statement
1283     * is not an <code>INSERT</code> statement.
1284     *
1285     * @param sql an SQL <code>INSERT</code>, <code>UPDATE</code> or
1286     * <code>DELETE</code> statement or an SQL statement that returns nothing
1287     * @param columnNames an array of the names of the columns that should be
1288     * returned from the inserted row
1289     * @return either the row count for <code>INSERT</code>, <code>UPDATE</code>,
1290     * or <code>DELETE</code> statements, or 0 for SQL statements
1291     * that return nothing
1292     * @throws java.sql.SQLException if a database access error occurs, the SQL
1293     * statement returns a <code>ResultSet</code> object, or the
1294     * second argument supplied to this method is not a <code>String</code> array
1295     * whose elements are valid column names
1296     * @since 1.4
1297     */

1298    public int executeUpdate(String JavaDoc sql, String JavaDoc columnNames[]) throws SQLException JavaDoc {
1299        return wrappedStatement.executeUpdate(sql, columnNames);
1300    }
1301
1302    /**
1303     * Executes the given SQL statement, which may return multiple results,
1304     * and signals the driver that the
1305     * auto-generated keys indicated in the given array should be made available
1306     * for retrieval. This array contains the names of the columns in the
1307     * target table that contain the auto-generated keys that should be made
1308     * available. The driver will ignore the array if the given SQL statement
1309     * is not an <code>INSERT</code> statement.
1310     * <p>
1311     * In some (uncommon) situations, a single SQL statement may return
1312     * multiple result sets and/or update counts. Normally you can ignore
1313     * this unless you are (1) executing a stored procedure that you know may
1314     * return multiple results or (2) you are dynamically executing an
1315     * unknown SQL string.
1316     * <p>
1317     * The <code>execute</code> method executes an SQL statement and indicates the
1318     * form of the first result. You must then use the methods
1319     * <code>getResultSet</code> or <code>getUpdateCount</code>
1320     * to retrieve the result, and <code>getMoreResults</code> to
1321     * move to any subsequent result(s).
1322     *
1323     * @param sql any SQL statement
1324     * @param columnNames an array of the names of the columns in the inserted
1325     * row that should be made available for retrieval by a call to the
1326     * method <code>getGeneratedKeys</code>
1327     * @return <code>true</code> if the next result is a <code>ResultSet</code>
1328     * object; <code>false</code> if it is an update count or there
1329     * are no more results
1330     * @throws java.sql.SQLException if a database access error occurs or the
1331     * elements of the <code>String</code> array passed to this
1332     * method are not valid column names
1333     * @see #getResultSet
1334     * @see #getUpdateCount
1335     * @see #getMoreResults
1336     * @see #getGeneratedKeys
1337     * @since 1.4
1338     */

1339    public boolean execute(String JavaDoc sql, String JavaDoc columnNames[]) throws SQLException JavaDoc {
1340        return wrappedStatement.execute(sql, columnNames);
1341    }
1342
1343    // ---------------------------------------------------------------- output
1344

1345    /**
1346     * Returns the sql statement string (question marks replaced with set parameter values)
1347     * that will be (or has been) executed by the {@link java.sql.PreparedStatement PreparedStatement} that this
1348     * <code>LoggablePreparedStatement</code> is a wrapper for.
1349
1350     * @return the statemant represented by this <code>LoggablePreparedStatement</code>
1351     */

1352    public String JavaDoc getQueryString() {
1353        StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
1354        int qMarkCount = 0;
1355        StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc(sqlTemplate + ' ', "?");
1356        while (tok.hasMoreTokens()) {
1357            String JavaDoc oneChunk = tok.nextToken();
1358            buf.append(oneChunk);
1359            try {
1360                Object JavaDoc value;
1361                if (parameterValues.size() > 1 + qMarkCount) {
1362                    value = parameterValues.get(1 + qMarkCount);
1363                    qMarkCount++;
1364                } else {
1365                    if (tok.hasMoreTokens()) {
1366                        value = null;
1367                    } else {
1368                        value = "";
1369                    }
1370                }
1371                buf.append(value);
1372            } catch (Throwable JavaDoc th) {
1373                buf.append("--- Exception occurs while creating query string for log: ").append(th.toString());
1374            }
1375        }
1376        return buf.toString().trim();
1377    }
1378
1379    /**
1380     * Saves the parameter value <code>obj</code> for the specified <code>position</code> for use in logging output
1381     *
1382     * @param position position (starting at 1) of the parameter to save
1383     * @param obj java.lang.Object the parameter value to save
1384     */

1385    private void saveQueryParamValue(int position, Object JavaDoc obj) {
1386        String JavaDoc strValue;
1387        if (obj instanceof String JavaDoc || obj instanceof Date JavaDoc) {
1388            strValue = "'" + obj + '\''; // if we have a String or Date , include '' in the saved value
1389
} else {
1390
1391            if (obj == null) {
1392                strValue = "<null>"; // convert null to the string null
1393
} else {
1394                strValue = obj.toString(); // unknown object (includes all Numbers), just call toString
1395
}
1396        }
1397
1398        // if we are setting a position larger than current size of parameterValues, first make it larger
1399
while (position >= parameterValues.size()) {
1400            parameterValues.add(null);
1401        }
1402        parameterValues.set(position, strValue);
1403    }
1404}
1405
Popular Tags