Source code: org/hsqldb/jdbcPreparedStatement.java
1 /* Copyrights and Licenses
2 *
3 * This product includes Hypersonic SQL.
4 * Originally developed by Thomas Mueller and the Hypersonic SQL Group.
5 *
6 * Copyright (c) 1995-2000 by the Hypersonic SQL Group. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without modification, are permitted
8 * provided that the following conditions are met:
9 * - Redistributions of source code must retain the above copyright notice, this list of conditions
10 * and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright notice, this list of
12 * conditions and the following disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 * - All advertising materials mentioning features or use of this software must display the
15 * following acknowledgment: "This product includes Hypersonic SQL."
16 * - Products derived from this software may not be called "Hypersonic SQL" nor may
17 * "Hypersonic SQL" appear in their names without prior written permission of the
18 * Hypersonic SQL Group.
19 * - Redistributions of any form whatsoever must retain the following acknowledgment: "This
20 * product includes Hypersonic SQL."
21 * This software is provided "as is" and any expressed or implied warranties, including, but
22 * not limited to, the implied warranties of merchantability and fitness for a particular purpose are
23 * disclaimed. In no event shall the Hypersonic SQL Group or its contributors be liable for any
24 * direct, indirect, incidental, special, exemplary, or consequential damages (including, but
25 * not limited to, procurement of substitute goods or services; loss of use, data, or profits;
26 * or business interruption). However caused any on any theory of liability, whether in contract,
27 * strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this
28 * software, even if advised of the possibility of such damage.
29 * This software consists of voluntary contributions made by many individuals on behalf of the
30 * Hypersonic SQL Group.
31 *
32 *
33 * For work added by the HSQL Development Group:
34 *
35 * Copyright (c) 2001-2002, The HSQL Development Group
36 * All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions are met:
40 *
41 * Redistributions of source code must retain the above copyright notice, this
42 * list of conditions and the following disclaimer, including earlier
43 * license statements (above) and comply with all above license conditions.
44 *
45 * Redistributions in binary form must reproduce the above copyright notice,
46 * this list of conditions and the following disclaimer in the documentation
47 * and/or other materials provided with the distribution, including earlier
48 * license statements (above) and comply with all above license conditions.
49 *
50 * Neither the name of the HSQL Development Group nor the names of its
51 * contributors may be used to endorse or promote products derived from this
52 * software without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
55 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL HSQL DEVELOPMENT GROUP, HSQLDB.ORG,
58 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
59 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
60 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
61 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
62 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
63 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
64 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65 */
66
67
68 package org.hsqldb;
69
70 import java.io.IOException;
71 import java.io.InputStream;
72 import java.io.Reader;
73 import java.math.BigDecimal;
74 import java.sql.*; // for Array, Blob, Clob, Ref
75 import java.sql.CallableStatement;
76 import java.sql.PreparedStatement;
77 import java.sql.ResultSet;
78 import java.sql.ResultSetMetaData;
79 import java.sql.SQLException;
80 import java.sql.Time;
81 import java.sql.Timestamp;
82 import java.sql.Types;
83 import java.util.*; // for Map
84 import java.util.Calendar;
85 import java.util.Vector;
86 import org.hsqldb.lib.HsqlDateTime;
87
88 // fredt@users 20020320 - patch 1.7.0 - JDBC 2 support and error trapping
89 // JDBC 2 methods can now be called from jdk 1.1.x - see javadoc comments
90 // boucherb@users 20020509 - added "throws SQLException" to all methods where
91 // it was missing here but specified in the java.sql.PreparedStatement and
92 // java.sqlCallableStatement interfaces, updated generic documentation to
93 // JDK 1.4, and added JDBC3 methods and docs
94 // boucherb@users and fredt@users 20020409/20020505 extensive review and update
95 // of docs and behaviour to comply with previous and latest java.sql specification
96
97 /**
98 * <!-- start Release-specific documentation -->
99 * Implements both the <CODE>java.sql.PreparedStatement</CODE> and
100 * <CODE>java.sql.CallableStatement</CODE> interfaces. <p>
101 *
102 * <span class="ReleaseSpecificDocumentation">
103 * In short: <p>
104 *
105 * <UL>
106 * <LI>A <CODE>PreparedStatement</CODE> is used to precompile and
107 * execute SQL statements, possibly using parameters.</LI>
108 * <LI>A <CODE>CallableStatement</CODE> is used to execute SQL
109 * stored procedures.</LI>
110 * </UL>
111 * <p>
112 *
113 * The following is composed of three sections:
114 * <OL>
115 * <LI>The generic overview for <CODE>PreparedStatement</CODE>.</LI>
116 * <LI>The generic overview for <CODE>CallableStatement</CODE>.</LI>
117 * <LI>A discussion of some HSQLDB-specific concerns.</LI>
118 * </OL>
119 * </span> <p>
120 * <!-- end Release-specific documentation -->
121 *
122 * <!-- start generic PreparedStatement documentation -->
123 * <B>From <CODE>PreparedStatement</CODE>:</B><p>
124 *
125 * An object that represents a precompiled SQL statement. <p>
126 *
127 * A SQL statement is precompiled and stored in a
128 * <code>PreparedStatement</code> object. This object can then be used to
129 * efficiently execute this statement multiple times.
130 *
131 * <P><B>Note:</B> The setter methods (<code>setShort</code>,
132 * <code>setString</code>, and so on) for setting IN parameter values
133 * must specify types that are compatible with the defined SQL type of
134 * the input parameter. For instance, if the IN parameter has SQL type
135 * <code>INTEGER</code>, then the method <code>setInt</code> should be
136 * used. <p>
137 *
138 * If arbitrary parameter type conversions are required, the method
139 * <code>setObject</code> should be used with a target SQL type.
140 * <P>
141 * In the following example of setting a parameter, <code>con</code>
142 * represents an active connection:
143 * <PRE>
144 * PreparedStatement pstmt = con.prepareStatement("UPDATE EMPLOYEES
145 * SET SALARY = ? WHERE ID = ?");
146 * pstmt.setBigDecimal(1, 153833.00)
147 * pstmt.setInt(2, 110592)
148 * </PRE> <p>
149 * <!-- end generic PreparedStatement documentation -->
150 *
151 * <!-- start generic CallableStatement documentation -->
152 * <B>From <CODE>CallableStatement</CODE>:</B><p>
153 *
154 * The interface used to execute SQL stored procedures. <p>
155 *
156 * The JDBC API provides a stored procedure SQL escape syntax that
157 * allows stored procedures to be called in a standard way for all
158 * RDBMSs. This escape syntax has one form that includes a result
159 * parameter and one that does not. If used, the result parameter must
160 * be registered as an OUT parameter. The other parameters
161 * can be used for input, output or both. Parameters are referred to
162 * sequentially, by number, with the first parameter being 1.
163 * <PRE>
164 * {?= call <procedure-name>[<arg1>,<arg2>, ...]}
165 * {call <procedure-name>[<arg1>,<arg2>, ...]}
166 * </PRE>
167 * <P>
168 * IN parameter values are set using the <code>set</code> methods
169 * inherited from <a href=
170 * "http://java.sun.com/j2se/1.4/docs/api/java/sql/PreparedStatement.html"
171 * ><CODE>PreparedStatement</CODE></a>. The type of all
172 * OUT parameters must be registered prior to executing the stored
173 * procedure; their values are retrieved after execution via the
174 * <code>get</code> methods provided here.
175 * <P>
176 * A <code>CallableStatement</code> can return one <a href=
177 * "http://java.sun.com/j2se/1.4/docs/api/java/sql/ResultSet.html">
178 * <CODE>ResultSet</CODE></a> object or multiple <code>ResultSet</code>
179 * objects. Multiple <code>ResultSet</code> objects are handled using
180 * operations inherited from <a href="
181 * http://java.sun.com/j2se/1.4/docs/api/java/sql/Statement.html">
182 * <CODE>Statement</CODE></a>.
183 * <P>
184 * For maximum portability, a call's <code>ResultSet</code> objects and
185 * update counts should be processed prior to getting the values of
186 * output parameters. <p>
187 * <!-- end generic CallableStatement documentation -->
188 *
189 * <!-- start Release-specific documentation -->
190 * <span class="ReleaseSpecificDocumentation">
191 * <B>HSQLDB-Specific Information:</B> <p>
192 *
193 * Up to and including HSQLDB 1.7.0, support for stored procedures is
194 * not provided in the conventional fashion, if there is such a thing. <p>
195 *
196 * Stored procedures are typically supported in ways that vary greatly
197 * from one DBMS implementation to the next. So, it is almost
198 * guaranteed that the code for a stored procedure written under a
199 * specific DBMS product will not work without modification in the
200 * context of another vendor's product or even across a single vendor's
201 * product lines. Moving stored procedures from one DBMS product line to
202 * another almost invariably involves complex porting issues and often
203 * may not be possible at all. Be warned. <p>
204 *
205 * HSQLDB stored procedures map directly onto the methods of compiled
206 * Java classes found on the classpath of the engine. This is done in
207 * a non-standard but fairly efficient way by issuing a class grant (and
208 * possibly method aliases) of the form: <p>
209 *
210 * <PRE>
211 * GRANT ALL ON CLASS "package.class" TO [user_name | PUBLIC]
212 * CREATE ALIAS call_name FOR ""package.class.method" -- optional
213 * </PRE>
214 *
215 * This has the effect of allowing the specified user(s) to access all
216 * of the public static methods of the specified class in either the role
217 * of SQL functions or stored procedures. For example:
218 *
219 * <PRE>
220 * GRANT ALL ON CLASS "java.lang.Math" TO PUBLIC;
221 * CONNECT anyuser PASSWORD *****;
222 * SELECT "java.lang.Math.abs"(column_1) FROM table_1;
223 * CREATE ALIAS abs FOR "java.lang.Math.abs"
224 * CALL abs(-5);
225 * </PRE>
226 *
227 * However, no support for more advanced features is provided at this
228 * time. That is, the <CODE>CallableStatement</CODE> methods for working
229 * with <CODE>OUT</CODE> parameters are not yet supported because--at a
230 * lower level--in all cases the HSQLDB database engine notes and returns
231 * <i>only</i> the result set or update count generated by executing a
232 * statement. <p>
233 *
234 * So, while some systems may <I>require</I> working with <CODE>OUT</CODE>
235 * parameters when calling stored procedures, this is currently never
236 * the case for HSQLDB; attempting to do so will always result in
237 * throwing a <CODE>SQLException</CODE>, stating that the function
238 * is not supported. <p>
239 *
240 * Please also note that the HSQLDB stored procedure mechanism is essentially
241 * a wrap of the HSQLDB SQL function mechanism, simply allowing Java methods to
242 * be called outside of an <CODE>INSERT</CODE>, <CODE>UPDATE</CODE>,
243 * <CODE>DELETE</CODE> or <CODE>SELECT</CODE> statement context.
244 * That is, issuing any <CODE>CALL</CODE> statement has virtually the
245 * the same effect as:
246 *
247 * <PRE>
248 * CREATE TABLE DUAL (dummy VARCHAR);
249 * INSERT INTO DUAL VALUES NULL;
250 * SELECT "package.class.method"(paramter_list) FROM DUAL;
251 * </PRE>
252 *
253 * In other words, HSQLDB does not yet support stored procedures that
254 * return true result sets. Instead, Java methods invoked as
255 * HSQLDB stored procedures <I>must</I> return a single value that is
256 * compatible with a supported HSQLDB SQL type. Furthermore, the
257 * return value is always wrapped in a result object with one column
258 * and one row, before it is handed off to client code.<p>
259 *
260 * This behviour will definitely change in 1.7.1 and above, in that HSQLDB
261 * will also allow stored procedures to return a single, true result set.
262 * However, it is uncertain at this time when/if support for <code>OUT</code>
263 * parameters will be introduced. <p>
264 *
265 * <b>JRE 1.1.x Notes:</b> <p>
266 *
267 * In general, JDBC 2 support requires Java 1.2 and above, and JDBC3 requires
268 * Java 1.4 and above. In HSQLDB, support for methods introduced in different
269 * versions of JDBC depends on the JDK version used for compiling and building
270 * HSQLDB.<p>
271 *
272 * Since 1.7.0, it is possible to build the product so that
273 * all JDBC 2 methods can be called while executing under the version 1.1.x
274 * <em>Java Runtime Environment</em><sup><font size="-2">TM</font></sup>.
275 * However, some of these method calls require <code>int</code> values that
276 * are defined only in the JDBC 2 or greater version of
277 * <a href="http://java.sun.com/j2se/1.4/docs/api/java/sql/ResultSet.html">
278 * <CODE>ResultSet</CODE></a> interface. For this reason, when the
279 * product is compiled under JDK 1.1.x, these values are defined in
280 * {@link jdbcResultSet jdbcResultSet}.<p>
281 *
282 * In a JRE 1.1.x environment, calling JDBC 2 methods that take or return the
283 * JDBC2-only <CODE>ResultSet</CODE> values can be achieved by referring
284 * to them in parameter specifications and return value comparisons,
285 * respectively, as follows: <p>
286 *
287 * <CODE class="JavaCodeExample">
288 * jdbcResultSet.FETCH_FORWARD<br>
289 * jdbcResultSet.TYPE_FORWARD_ONLY<br>
290 * jdbcResultSet.TYPE_SCROLL_INSENSITIVE<br>
291 * jdbcResultSet.CONCUR_READ_ONLY<br>
292 * </CODE> <p>
293 *
294 * However, please note that code written in such a manner will not be
295 * compatible for use with other JDBC 2 drivers, since they expect and use
296 * <code>ResultSet</code>, rather than <code>jdbcResultSet</code>. Also
297 * note, this feature is offered solely as a convenience to developers
298 * who must work under JDK 1.1.x due to operating constraints, yet wish to
299 * use some of the more advanced features available under the JDBC 2
300 * specification.<p>
301 *
302 * (fredt@users)<br>
303 * (boucherb@users)<p>
304 *
305 * </span>
306 * <!-- end Release-specific documentation -->
307 *
308 * @see jdbcConnection#prepareStatement
309 * @see jdbcConnection#prepareCall
310 * @see jdbcResultSet
311 */
312 public class jdbcPreparedStatement extends org.hsqldb.jdbcStatement
313 implements java.sql.PreparedStatement, java.sql.CallableStatement {
314
315 /**
316 * The SQL query this object represents.
317 */
318 private String sSql;
319
320 /**
321 * The list of values used to replace the parameters of the SQL statement
322 * this object represents
323 */
324 private Vector vParameter;
325
326 // fredt@users 20020215 - patch 517028 by peterhudson@users - method defined
327 // fredt@users 20020215 - patch 517028 by peterhudson@users - method defined
328 //
329 // changes by fredt
330 // SimpleDateFormat objects moved out of methods to improve performance
331 // this is safe because only one thread at a time should access a
332 // PreparedStatement object until it has finished executing the statement
333 // fredt@users 20020215 - patch 517028 by peterhudson@users - method defined
334 // minor changes by fredt
335
336 /**
337 * <!-- start generic documentation -->
338 * Sets escape processing on or off. <p>
339 * <!-- end generic documentation -->
340 *
341 * <!-- start release-specific documentation -->
342 * <span class="ReleaseSpecificDocumentation">
343 * <b>HSQLDB-Specific Information:</b> <p>
344 *
345 * HSQLDB 1.7.0 follows the standard behaviour by overriding the same
346 * method in jdbcStatement class. <p>
347 *
348 * Calling this method will have no effect.
349 *
350 * </span>
351 * <!-- end release-specific documentation -->
352 *
353 * @param enable <code>true</code> to enable escape processing;
354 * <code>false</code> to disable it
355 * @exception SQLException if a database access error occurs
356 */
357 // fredt@users 20020428 - patch 1.7.0 - method orerrides the one in jdbcStatement
358 public void setEscapeProcessing(boolean enable) throws SQLException {
359
360 if (Trace.TRACE) {
361 Trace.trace();
362 }
363
364 checkClosed();
365
366 // do not change the bEscapeProcessing
367 // bEscapeProcessing = enable;
368 }
369
370 /**
371 * <!-- start generic documentation -->
372 * Executes the SQL query in this <code>PreparedStatement</code> object
373 * and returns the <code>ResultSet</code> object generated by the query.<p>
374 * <!-- end generic documentation -->
375 *
376 * <!-- start release-specific documentation -->
377 * <span class="ReleaseSpecificDocumentation">
378 * </span>
379 *
380 * @return a <code>ResultSet</code> object that contains the data produced
381 * by the query; never <code>null</code>
382 * @exception SQLException if a database access error occurs or the SQL
383 * statement does not return a <code>ResultSet</code> object
384 */
385 public ResultSet executeQuery() throws SQLException {
386
387 if (Trace.TRACE) {
388 Trace.trace();
389 }
390
391 return super.executeQuery(build());
392 }
393
394 /**
395 * <!-- start generic documentation -->
396 * Executes the SQL statement in this <code>PreparedStatement</code>
397 * object, which must be an SQL <code>INSERT</code>,
398 * <code>UPDATE</code> or <code>DELETE</code> statement; or an SQL
399 * statement that returns nothing, such as a DDL statement.<p>
400 * <!-- end generic documentation -->
401 *
402 * <!-- start release-specific documentation -->
403 * <span class="ReleaseSpecificDocumentation">
404 * </span>
405 *
406 * @return either (1) the row count for <code>INSERT</code>,
407 * <code>UPDATE</code>, or <code>DELETE</code>
408 * statements or (2) 0 for SQL statements that
409 * return nothing
410 * @exception SQLException if a database access error occurs or the SQL
411 * statement returns a <code>ResultSet</code> object
412 */
413 public int executeUpdate() throws SQLException {
414
415 if (Trace.TRACE) {
416 Trace.trace();
417 }
418
419 return super.executeUpdate(build());
420 }
421
422 /**
423 * <!-- start generic documentation -->
424 * Sets the designated parameter to SQL <code>NULL</code>. <p>
425 *
426 * <B>Note:</B> You must specify the parameter's SQL type.<p>
427 * <!-- end generic documentation -->
428 *
429 * <!-- start release-specific documentation -->
430 * <span class="ReleaseSpecificDocumentation">
431 * </span>
432 *
433 * @param parameterIndex the first parameter is 1, the second is 2, ...
434 * @param sqlType the SQL type code defined in <code>java.sql.Types</code>
435 * @exception SQLException if a database access error occurs
436 */
437 public void setNull(int parameterIndex, int sqlType) throws SQLException {
438
439 if (Trace.TRACE) {
440 Trace.trace();
441 }
442
443 setNull(parameterIndex);
444 }
445
446 /**
447 * <!-- start generic documentation -->
448 * Sets the designated parameter to the given Java <code>boolean</code>
449 * value. The driver converts this to an SQL <code>BIT</code> value
450 * when it sends it to the database.<p>
451 * <!-- end generic documentation -->
452 *
453 * <!-- start release-specific documentation -->
454 * <span class="ReleaseSpecificDocumentation">
455 * </span>
456 *
457 * @param parameterIndex the first parameter is 1, the second is 2, ...
458 * @param x the parameter value
459 * @exception SQLException if a database access error occurs
460 */
461 public void setBoolean(int parameterIndex,
462 boolean x) throws SQLException {
463
464 if (Trace.TRACE) {
465 Trace.trace();
466 }
467
468 setParameter(parameterIndex, x ? "TRUE"
469 : "FALSE");
470 }
471
472 /**
473 * <!-- start generic documentation -->
474 * Sets the designated parameter to the given Java <code>byte</code> value.
475 * The driver converts this to an SQL <code>TINYINT</code> value when
476 * it sends it to the database.<p>
477 * <!-- end generic documentation -->
478 *
479 * <!-- start release-specific documentation -->
480 * <span class="ReleaseSpecificDocumentation">
481 * </span>
482 *
483 * @param parameterIndex the first parameter is 1, the second is 2, ...
484 * @param x the parameter value
485 * @exception SQLException if a database access error occurs
486 */
487 public void setByte(int parameterIndex, byte x) throws SQLException {
488
489 if (Trace.TRACE) {
490 Trace.trace();
491 }
492
493 setParameter(parameterIndex, String.valueOf(x));
494 }
495
496 /**
497 * <!-- start generic documentation -->
498 * Sets the designated parameter to the given Java <code>short</code>
499 * value. The driver converts this to an SQL <code>SMALLINT</code>
500 * value when it sends it to the database.<p>
501 * <!-- end generic documentation -->
502 *
503 * <!-- start release-specific documentation -->
504 * <span class="ReleaseSpecificDocumentation">
505 * </span>
506 *
507 * @param parameterIndex the first parameter is 1, the second is 2, ...
508 * @param x the parameter value
509 * @exception SQLException if a database access error occurs
510 */
511 public void setShort(int parameterIndex, short x) throws SQLException {
512
513 if (Trace.TRACE) {
514 Trace.trace();
515 }
516
517 setParameter(parameterIndex, String.valueOf(x));
518 }
519
520 /**
521 * <!-- start generic documentation -->
522 * Sets the designated parameter to the given Java <code>int</code> value.
523 * The driver converts this to an SQL <code>INTEGER</code> value when
524 * it sends it to the database.<p>
525 * <!-- end generic documentation -->
526 *
527 * <!-- start release-specific documentation -->
528 * <span class="ReleaseSpecificDocumentation">
529 * </span>
530 *
531 * @param parameterIndex the first parameter is 1, the second is 2, ...
532 * @param x the parameter value
533 * @exception SQLException if a database access error occurs
534 */
535 public void setInt(int parameterIndex, int x) throws SQLException {
536
537 if (Trace.TRACE) {
538 Trace.trace();
539 }
540
541 setParameter(parameterIndex, String.valueOf(x));
542 }
543
544 /**
545 * <!-- start generic documentation -->
546 * Sets the designated parameter to the given Java <code>long</code> value.
547 * The driver converts this to an SQL <code>BIGINT</code> value when
548 * it sends it to the database.<p>
549 * <!-- end generic documentation -->
550 *
551 * <!-- start release-specific documentation -->
552 * <span class="ReleaseSpecificDocumentation">
553 * </span>
554 *
555 * @param parameterIndex the first parameter is 1, the second is 2, ...
556 * @param x the parameter value
557 * @exception SQLException if a database access error occurs
558 */
559 public void setLong(int parameterIndex, long x) throws SQLException {
560
561 if (Trace.TRACE) {
562 Trace.trace();
563 }
564
565 setParameter(parameterIndex, String.valueOf(x));
566 }
567
568 /**
569 * <!-- start generic documentation -->
570 * Sets the designated parameter to the given Java <code>float</code> value.
571 * The driver converts this to an SQL <code>FLOAT</code> value when
572 * it sends it to the database.<p>
573 * <!-- end generic documentation -->
574 *
575 * <!-- start release-specific documentation -->
576 * <span class="ReleaseSpecificDocumentation">
577 * <b>HSQLDB-Specific Information:</b> <p>
578 *
579 * Up to 1.6.1, HSQLDB did not handle Java positive/negative Infinity or
580 * NaN <code>float</code> values properly. With 1.7.0,
581 * these values are converted to SQL <code>NULL</code>. With 1.7.1 these
582 * values are sent to the database.
583 * </span>
584 *
585 * @param parameterIndex the first parameter is 1, the second is 2, ...
586 * @param x the parameter value
587 * @exception SQLException if a database access error occurs
588 */
589
590 // fredt@users 20020325 - patch 448691 NaN by fredt
591 // fredt@users 20021013 - patch 1.7.1 - NaN and infinity preserved
592 public void setFloat(int parameterIndex, float x) throws SQLException {
593
594 if (Trace.TRACE) {
595 Trace.trace();
596 }
597
598 setParameter(parameterIndex, Column.createSQLString(x));
599 /*
600 if (Float.isInfinite(x) || Float.isNaN(x)) {
601 setNull(parameterIndex);
602 } else {
603 String s = String.valueOf(x);
604
605 // ensure the engine treats the value as a DOUBLE, not DECIMAL
606 if (s.indexOf('E') < 0) {
607 s = s.concat("E0");
608 }
609
610 setParameter(parameterIndex, s);
611 }
612 */
613 }
614
615 /**
616 * <!-- start generic documentation -->
617 * Sets the designated parameter to the given Java <code>double</code> value.
618 * The driver converts this to an SQL <code>DOUBLE</code> value when it
619 * sends it to the database.<p>
620 * <!-- end generic documentation -->
621 *
622 * <!-- start release-specific documentation -->
623 * <span class="ReleaseSpecificDocumentation">
624 * <b>HSQLDB-Specific Information:</b> <p>
625 *
626 * Up to 1.6.1, HSQLDB did not handle Java positive/negative Infinity or
627 * NaN <code>float</code> values properly. With 1.7.0,
628 * these values are converted to SQL <code>NULL</code>. With 1.7.1 these
629 * values are sent to the database.
630 * </span>
631 *
632 * @param parameterIndex the first parameter is 1, the second is 2, ...
633 * @param x the parameter value
634 * @exception SQLException if a database access error occurs
635 */
636
637 // fredt@users 20020325 - patch 448691 NaN by fredt
638 // fredt@users 20021013 - patch 1.7.1 - NaN and infinity preserved
639 public void setDouble(int parameterIndex, double x) throws SQLException {
640
641 if (Trace.TRACE) {
642 Trace.trace();
643 }
644
645 setParameter(parameterIndex, Column.createSQLString(x));
646 /*
647 if (Double.isInfinite(x) || Double.isNaN(x)) {
648 setNull(parameterIndex);
649 } else {
650 String s = String.valueOf(x);
651
652 // ensure the engine treats the value as a DOUBLE, not DECIMAL
653 if (s.indexOf('E') < 0) {
654 s = s.concat("E0");
655 }
656
657 setParameter(parameterIndex, s);
658 }
659 */
660 }
661
662 /**
663 * <!-- start generic documentation -->
664 * Sets the designated parameter to the given
665 * <code>java.math.BigDecimal</code> value.
666 * The driver converts this to an SQL <code>NUMERIC</code> value when
667 * it sends it to the database.<p>
668 * <!-- end generic documentation -->
669 *
670 * <!-- start release-specific documentation -->
671 * <span class="ReleaseSpecificDocumentation">
672 * </span>
673 *
674 * @param parameterIndex the first parameter is 1, the second is 2, ...
675 * @param x the parameter value
676 * @exception SQLException if a database access error occurs
677 */
678 public void setBigDecimal(int parameterIndex,
679 BigDecimal x) throws SQLException {
680
681 if (Trace.TRACE) {
682 Trace.trace();
683 }
684
685 setParameter(parameterIndex,
686 Column.createSQLString(x, Types.DECIMAL));
687 }
688
689 /**
690 * <!-- start generic documentation -->
691 * Sets the designated parameter to the given Java <code>String</code> value.
692 * The driver converts this
693 * to an SQL <code>VARCHAR</code> or <code>LONGVARCHAR</code> value
694 * (depending on the argument's
695 * size relative to the driver's limits on <code>VARCHAR</code> values)
696 * when it sends it to the database.<p>
697 * <!-- end generic documentation -->
698 *
699 * <!-- start release-specific documentation -->
700 * <span class="ReleaseSpecificDocumentation">
701 * </span>
702 *
703 * @param parameterIndex the first parameter is 1, the second is 2, ...
704 * @param x the parameter value
705 * @exception SQLException if a database access error occurs
706 */
707 public void setString(int parameterIndex, String x) throws SQLException {
708
709 if (Trace.TRACE) {
710 Trace.trace();
711 }
712
713 setParameter(parameterIndex, Column.createSQLString(x));
714 }
715
716 /**
717 * <!-- start generic documentation -->
718 * Sets the designated parameter to the given Java array of bytes.
719 * The driver converts this to an SQL <code>VARBINARY</code> or
720 * <code>LONGVARBINARY</code> (depending on the argument's size relative
721 * to the driver's limits on <code>VARBINARY</code> values) when it
722 * sends it to the database.<p>
723 * <!-- end generic documentation -->
724 *
725 * <!-- start release-specific documentation -->
726 * <span class="ReleaseSpecificDocumentation">
727 * </span>
728 *
729 * @param parameterIndex the first parameter is 1, the second is 2, ...
730 * @param x the parameter value
731 * @exception SQLException if a database access error occurs
732 */
733 public void setBytes(int parameterIndex, byte x[]) throws SQLException {
734
735 if (Trace.TRACE) {
736 Trace.trace();
737 }
738
739 if (x == null) {
740 setNull(parameterIndex);
741 } else {
742 setParameter(
743 parameterIndex,
744 Column.createSQLString(StringConverter.byteToHex(x)));
745 }
746 }
747
748 /**
749 * <!-- start generic documentation -->
750 * Sets the designated parameter to the given
751 * <code>java.sql.Date</code> value. The driver converts this
752 * to an SQL <code>DATE</code> value when it sends it to the database.<p>
753 * <!-- end generic documentation -->
754 *
755 * <!-- start release-specific documentation -->
756 * <span class="ReleaseSpecificDocumentation">
757 * </span>
758 *
759 * @param parameterIndex the first parameter is 1, the second is 2, ...
760 * @param x the parameter value
761 * @exception SQLException if a database access error occurs
762 */
763 public void setDate(int parameterIndex,
764 java.sql.Date x) throws SQLException {
765
766 if (Trace.TRACE) {
767 Trace.trace();
768 }
769
770 setParameter(parameterIndex, Column.createSQLString(x, Types.DATE));
771 }
772
773 /**
774 * <!-- start generic documentation -->
775 * Sets the designated parameter to the given <code>java.sql.Time</code>
776 * value. The driver converts this to an SQL <code>TIME</code> value when it
777 * sends it to the database.<p>
778 * <!-- end generic documentation -->
779 *
780 * <!-- start release-specific documentation -->
781 * <span class="ReleaseSpecificDocumentation">
782 * </span>
783 *
784 * @param parameterIndex the first parameter is 1, the second is 2, ...
785 * @param x the parameter value
786 * @exception SQLException if a database access error occurs
787 */
788 public void setTime(int parameterIndex,
789 java.sql.Time x) throws SQLException {
790
791 if (Trace.TRACE) {
792 Trace.trace();
793 }
794
795 setParameter(parameterIndex, Column.createSQLString(x, Types.TIME));
796 }
797
798 /**
799 * <!-- start generic documentation -->
800 * Sets the designated parameter to the given
801 * <code>java.sql.Timestamp</code> value. The driver converts this to
802 * an SQL <code>TIMESTAMP</code> value when it sends it to the
803 * database.<p>
804 * <!-- end generic documentation -->
805 *
806 * <!-- start release-specific documentation -->
807 * <span class="ReleaseSpecificDocumentation">
808 * </span>
809 *
810 * @param parameterIndex the first parameter is 1, the second is 2, ...
811 * @param x the parameter value
812 * @exception SQLException if a database access error occurs
813 */
814 public void setTimestamp(int parameterIndex,
815 java.sql.Timestamp x) throws SQLException {
816
817 if (Trace.TRACE) {
818 Trace.trace();
819 }
820
821 setParameter(parameterIndex,
822 Column.createSQLString(x, Types.TIMESTAMP));
823 }
824
825 /**
826 * <!-- start generic documentation -->
827 * Sets the designated parameter to the given input stream, which will have
828 * the specified number of bytes.
829 * When a very large ASCII value is input to a <code>LONGVARCHAR</code>
830 * parameter, it may be more practical to send it via a
831 * <code>java.io.InputStream</code>. Data will be read from the stream
832 * as needed until end-of-file is reached. The JDBC driver will
833 * do any necessary conversion from ASCII to the database char format. <p>
834 *
835 * <b>Note:</b> This stream object can either be a standard
836 * Java stream object or your own subclass that implements the
837 * standard interface.<p>
838 * <!-- end generic documentation -->
839 * <!-- start release-specific documentation -->
840 * <span class="ReleaseSpecificDocumentation">
841 * <b>HSQLDB-Specific Information:</b> <p>
842 *
843 * This uses the default platform character encoding to convert bytes
844 * into characters of the String. In future this is likely to change to
845 * always treat the stream as ASCII.<p>
846 *
847 * Before HSQLDB 1.7.0, <code>setAsciiStream</code> and
848 * <code>setUnicodeStream</code> were identical.
849 * </span>
850 *
851 * @param parameterIndex the first parameter is 1, the second is 2, ...
852 * @param x the Java input stream that contains the ASCII parameter value
853 * @param length the number of bytes in the stream
854 * @exception SQLException if a database access error occurs
855 */
856 public void setAsciiStream(int parameterIndex, java.io.InputStream x,
857 int length) throws SQLException {
858
859 if (Trace.TRACE) {
860 Trace.trace();
861 }
862
863 if (x == null) {
864 setNull(parameterIndex);
865 } else {
866 setString(parameterIndex, StringConverter.inputStreamToString(x));
867 }
868 }
869
870 /**
871 * <!-- start generic documentation -->
872 * Sets the designated parameter to the given input stream, which
873 * will have the specified number of bytes. A Unicode character has
874 * two bytes, with the first byte being the high byte, and the second
875 * being the low byte.
876 *
877 * When a very large Unicode value is input to a <code>LONGVARCHAR</code>
878 * parameter, it may be more practical to send it via a
879 * <code>java.io.InputStream</code> object. The data will be read from the
880 * stream as needed until end-of-file is reached. The JDBC driver will
881 * do any necessary conversion from Unicode to the database char format.
882 *
883 * <P><B>Note:</B> This stream object can either be a standard
884 * Java stream object or your own subclass that implements the
885 * standard interface.<p>
886 * <!-- end generic documentation -->
887 *
888 * <!-- start release-specific documentation -->
889 * <span class="ReleaseSpecificDocumentation">
890 * <b>HSQLDB-Specific Information:</b> <p>
891 *
892 * Beginning with HSQLDB 1.7.0, this complies with JDBC3 specification.
893 * </span>
894 *
895 * @param parameterIndex the first parameter is 1, the second is 2, ...
896 * @param x a <code>java.io.InputStream</code> object that contains the
897 * Unicode parameter value as two-byte Unicode characters
898 * @param length the number of bytes in the stream
899 * @exception SQLException if a database access error occurs
900 * @deprecated Sun does not include a reason, but presumably setCharacterStream is now prefered?
901 */
902 public void setUnicodeStream(int parameterIndex, java.io.InputStream x,
903 int length) throws SQLException {
904
905 if (Trace.TRACE) {
906 Trace.trace();
907 }
908
909 StringBuffer sb = new StringBuffer(length / 2);
910
911 try {
912 for (int i = 0; i < sb.length(); i++) {
913 int c = x.read();
914
915 if (c == -1) {
916 break;
917 }
918
919 int c1 = x.read();
920
921 if (c1 == -1) {
922 break;
923 }
924
925 int character = c << 8 | c1;
926
927 sb.append(character);
928 }
929 } catch (IOException e) {
930 throw Trace.error(Trace.TRANSFER_CORRUPTED);
931 }
932
933 setParameter(parameterIndex, sb.toString());
934 }
935
936 /**
937 * <!-- start generic documentation -->
938 * Sets the designated parameter to the given input stream, which will have
939 * the specified number of bytes.
940 * When a very large binary value is input to a <code>LONGVARBINARY</code>
941 * parameter, it may be more practical to send it via a
942 * <code>java.io.InputStream</code> object. The data will be read from the
943 * stream as needed until end-of-file is reached.
944 *
945 * <P><B>Note:</B> This stream object can either be a standard
946 * Java stream object or your own subclass that implements the
947 * standard interface.<p>
948 * <!-- end generic documentation -->
949 *
950 * <!-- start release-specific documentation -->
951 * <span class="ReleaseSpecificDocumentation">
952 * <b>HSQLDB-Specific Information:</b> <p>
953 *
954 * Up to and including HSQLDB 1.7.0, a binary stream is converted to
955 * a SQL string consisting of hexidecimal digits that represent the
956 * stream. <p>
957 *
958 * <b>Example:</b> <p>
959 *
960 * <PRE>
961 * PreparedStatement ps =
962 * connection.prepareStatement("SELECT * FROM t WHERE col = ?");
963 * ps.setBinaryStream(1, myStream, 4);
964 * ps.execute();
965 * </PRE>
966 *
967 * Given that the first 4 bytes of the stream are 0xff, 0xff, 0xff, 0xff,
968 * the above code fragement would emit the following SQL:
969 *
970 * <PRE>
971 * SELECT * FROM t WHERE col = 'ffffffff'
972 * </PRE>
973 *
974 * Zero-length specifications result in zero bytes being read from the
975 * stream. In such cases, the parameter is compiled to an empty SQL
976 * string. If the length specified in the above code fragment was zero,
977 * the the emitted SQL would be:
978 *
979 * <PRE>
980 * SELECT * FROM t WHERE col = ''
981 * </PRE>
982 *
983 * This behaviour <i>may</i> change in a future release.
984 * </span>
985 *
986 * @param parameterIndex the first parameter is 1, the second is 2, ...
987 * @param x the java input stream which contains the binary parameter value
988 * @param length the number of bytes in the stream
989 * @exception SQLException if a database access error occurs
990 */
991 public void setBinaryStream(int parameterIndex, java.io.InputStream x,
992 int length) throws SQLException {
993
994 if (Trace.TRACE) {
995 Trace.trace();
996 }
997
998 // todo: is this correct?
999 // what if length=0?
1000 // fredt@users - that seems to be fine, zero length value
1001 byte b[] = new byte[length];
1002
1003 try {
1004 x.read(b, 0, length);
1005 x.close();
1006 } catch (IOException e) {
1007 throw Trace.error(Trace.INPUTSTREAM_ERROR, e.getMessage());
1008 }
1009
1010 setBytes(parameterIndex, b);
1011 }
1012
1013 /**
1014 * <!-- start generic documentation -->
1015 * Clears the current parameter values immediately. <p>
1016 *
1017 * In general, parameter values remain in force for repeated use of a
1018 * statement. Setting a parameter value automatically clears its
1019 * previous value. However, in some cases it is useful to immediately
1020 * release the resources used by the current parameter values; this can
1021 * be done by calling the method <code>clearParameters</code>.<p>
1022 * <!-- end generic documentation -->
1023 *
1024 * <!-- start release-specific documentation -->
1025 * <span class="ReleaseSpecificDocumentation">
1026 * </span>
1027 *
1028 * @exception SQLException if a database access error occurs
1029 */
1030 public void clearParameters() throws SQLException {
1031
1032 if (Trace.TRACE) {
1033 Trace.trace();
1034 }
1035
1036 vParameter.removeAllElements();
1037 }
1038
1039 //----------------------------------------------------------------------
1040 // Advanced features:
1041
1042 /**
1043 * <!-- start generic documentation -->
1044 * Sets the value of the designated parameter with the given object. <p>
1045 *
1046 * The second argument must be an object type; for integral values, the
1047 * <code>java.lang</code> equivalent objects should be used. <p>
1048 *
1049 * The given Java object will be converted to the given targetSqlType
1050 * before being sent to the database.
1051 *
1052 * If the object has a custom mapping (is of a class implementing the
1053 * interface <code>SQLData</code>),
1054 * the JDBC driver should call the method <code>SQLData.writeSQL</code> to
1055 * write it to the SQL data stream.
1056 * If, on the other hand, the object is of a class implementing
1057 * <code>Ref</code>, <code>Blob</code>, <code>Clob</code>,
1058 * <code>Struct</code>, or <code>Array</code>, the driver should pass it
1059 * to the database as a value of the corresponding SQL type. <p>
1060 *
1061 * Note that this method may be used to pass database-specific
1062 * abstract data types.<p>
1063 * <!-- end generic documentation -->
1064 *
1065 * <!-- start release-specific documentation -->
1066 * <span class="ReleaseSpecificDocumentation">
1067 * <b>HSQLDB-Specific Information:</b> <p>
1068 *
1069 * Up to and including HSQLDB 1.7.0, calling this method is identical to
1070 * calling
1071 * {@link #setObject(int, Object, int) setObject(int, Object, int)}.
1072 * That is, this method simply calls setObject(int, Object, int),
1073 * ignoring the scale specification.
1074 * </span>
1075 *
1076 * @param parameterIndex the first parameter is 1, the second is 2, ...
1077 * @param x the object containing the input parameter value
1078 * @param targetSqlType the SQL type (as defined in java.sql.Types) to be
1079 * sent to the database. The scale argument may further qualify this type.
1080 * @param scale for java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types,
1081 * this is the number of digits after the decimal point. For all
1082 * other types, this value will be ignored. <p>
1083 *
1084 * Up to and including HSQLDB 1.7.0, this parameter is ignored.
1085 * @exception SQLException if a database access error occurs
1086 * @see java.sql.Types
1087 */
1088 public void setObject(int parameterIndex, Object x, int targetSqlType,
1089 int scale) throws SQLException {
1090
1091 if (Trace.TRACE) {
1092 Trace.trace();
1093 }
1094
1095 setObject(parameterIndex, x, targetSqlType);
1096 }
1097
1098 /**
1099 * <!-- start generic documentation -->
1100 * Sets the value of the designated parameter with the given object.
1101 * This method is like the method <code>setObject</code>
1102 * above, except that it assumes a scale of zero. <p>
1103 * <!-- end generic documentation -->
1104 *
1105 * <!-- start release-specific documentation -->
1106 * <span class="ReleaseSpecificDocumentation">
1107 * <b>HSQLDB-Specific Information:</b> <p>
1108 *
1109 * Up to HSQLDB 1.6.1, this method did not work properly with all
1110 * combinations of object class and targetSqlType. <p>
1111 *
1112 * Starting with 1.7.0, this has been corrected. <p>
1113 *
1114 * </span>
1115 *
1116 * @param parameterIndex the first parameter is 1, the second is 2, ...
1117 * @param x the object containing the input parameter value
1118 * @param targetSqlType the SQL type (as defined in java.sql.Types) to be
1119 * sent to the database
1120 * @exception SQLException if a database access error occurs
1121 */
1122 public void setObject(int parameterIndex, Object x,
1123 int targetSqlType) throws SQLException {
1124
1125 if (Trace.TRACE) {
1126 Trace.trace();
1127 }
1128
1129 if (x == null) {
1130 setNull(parameterIndex);
1131
1132 return;
1133 }
1134
1135// fredt@users 20020328 - patch 482109 by fredt - OBJECT handling
1136 if (targetSqlType != Types.OTHER) {
1137 x = Column.convertObject(x, targetSqlType);
1138 }
1139
1140 setObjectInType(parameterIndex, x, targetSqlType);
1141 }
1142
1143 /**
1144 * <!-- start generic documentation -->
1145 * Sets the value of the designated parameter using the given object. <p>
1146 *
1147 * The second parameter must be of type <code>Object</code>; therefore,
1148 * the <code>java.lang</code> equivalent objects should be used for
1149 * built-in types. <p>
1150 *
1151 * The JDBC specification specifies a standard mapping from
1152 * Java <code>Object</code> types to SQL types. The given argument
1153 * will be converted to the corresponding SQL type before being
1154 * sent to the database. <p>
1155 *
1156 * Note that this method may be used to pass datatabase-
1157 * specific abstract data types, by using a driver-specific Java
1158 * type. If the object is of a class implementing the interface
1159 * <code>SQLData</code>, the JDBC driver should call the method
1160 * <code>SQLData.writeSQL</code> to write it to the SQL data stream.
1161 * If, on the other hand, the object is of a class implementing
1162 * <code>Ref</code>, <code>Blob</code>, <code>Clob</code>,
1163 * <code>Struct</code>, or <code>Array</code>, the driver should pass
1164 * it to the database as a value of the corresponding SQL type. <p>
1165 *
1166 * This method throws an exception if there is an ambiguity, for
1167 * example, if the object is of a class implementing more than one
1168 * of the interfaces named above.<p>
1169 * <!-- end generic documentation -->
1170 *
1171 * <!-- start release-specific documentation -->
1172 * <span class="ReleaseSpecificDocumentation">
1173 * <b>HSQLDB-Specific Information:</b><p>
1174 *
1175 * This method will call the apropriate setXXX method when it detects that
1176 * the specified Object is one that has a standard mapping to a
1177 * java.sql.Types type. However, if it known that the parameter will
1178 * correspond to a value for (or comparison against) a column of type
1179 * OTHER, then the method <code>setObject(i,x,Types.OTHER)</code>
1180 * should be used instead; in HSQLDB, columns of type OTHER are
1181 * reserved strictly for storing serialized Java Objects. That is,
1182 * when attempting to insert or update using values other than
1183 * null for OTHER column values, an exception is thrown if the value
1184 * is not a serializable Java Object. <p>
1185 *
1186 * </span>
1187 *
1188 * @param parameterIndex the first parameter is 1, the second is 2, ...
1189 * @param x the object containing the input parameter value
1190 * @exception SQLException if a database access error occurs or the type
1191 * of the given object is ambiguous
1192 */
1193 public void setObject(int parameterIndex, Object x) throws SQLException {
1194
1195 if (Trace.TRACE) {
1196 Trace.trace();
1197 }
1198
1199 if (x == null) {
1200 setNull(parameterIndex);
1201
1202 return;
1203 }
1204
1205 int type = Types.OTHER;
1206
1207 if (x instanceof String) {
1208 type = Types.VARCHAR;
1209 } else if (x instanceof BigDecimal) {
1210 type = Types.NUMERIC;
1211 } else if (x instanceof Integer) {
1212 type = Types.INTEGER;
1213 } else if (x instanceof Long) {
1214 type = Types.BIGINT;
1215 } else if (x instanceof Float) {
1216 type = Types.REAL;
1217 } else if (x instanceof Double) {
1218 type = Types.DOUBLE;
1219 } else if (x instanceof byte[]) {
1220 type = Types.BINARY;
1221 } else if (x instanceof java.sql.Date) {
1222 type = Types.DATE;
1223 } else if (x instanceof Time) {
1224 type = Types.TIME;
1225 } else if (x instanceof Timestamp) {
1226 type = Types.TIMESTAMP;
1227 } else if (x instanceof Boolean) {
1228 type = Types.BIT;
1229 } else if (x instanceof Byte) {
1230 type = Types.TINYINT;
1231 } else if (x instanceof Short) {
1232 type = Types.SMALLINT;
1233 }
1234
1235 setObjectInType(parameterIndex, x, type);
1236 }
1237
1238 /**
1239 * <!-- start generic documentation -->
1240 * Executes the SQL statement in this <code>PreparedStatement</code>
1241 * object, which may be any kind of SQL statement.
1242 * Some prepared statements return multiple results; the
1243 * <code>execute</code> method handles these complex statements as well
1244 * as the simpler form of statements handled by the methods
1245 * <code>executeQuery</code>and <code>executeUpdate</code>. <p>
1246 *
1247 * The <code>execute</code> method returns a <code>boolean</code> to
1248 * indicate the form of the first result. You must call either the method
1249 * <code>getResultSet</code> or <code>getUpdateCount</code>
1250 * to retrieve the result; you must call <code>getMoreResults</code> to
1251 * move to any subsequent result(s). <p>
1252 * <!-- end generic documentation -->
1253 *
1254 * <!-- start release-specific documentation -->
1255 * <span class="ReleaseSpecificDocumentation">
1256 * <b>HSQLDB-Specific Information:</b> <p>
1257 *
1258 * Up to and including HSQLDB 1.7.0, statements never return multiple
1259 * result sets. However, be aware that this behaviour <i>may</i>
1260 * change in a future release.
1261 * </span>
1262 *
1263 * @return <code>true</code> if the first result is a <code>ResultSet</code>
1264 * object; <code>false</code> if the first result is an update
1265 * count or there is no result
1266 * @exception SQLException if a database access error occurs or an argument
1267 * is supplied to this method
1268 * @see jdbcStatement#execute
1269 * @see jdbcStatement#getResultSet
1270 * @see jdbcStatement#getUpdateCount
1271 * @see jdbcStatement#getMoreResults
1272 */
1273 public boolean execute() throws SQLException {
1274
1275 if (Trace.TRACE) {
1276 Trace.trace();
1277 }
1278
1279 return super.execute(build());
1280 }
1281
1282 //--------------------------JDBC 2.0-----------------------------
1283
1284 /**
1285 * <!-- start generic documentation -->
1286 * Adds a set of parameters to this <code>PreparedStatement</code>
1287 * object's batch of commands. <p>
1288 * <!-- end generic documentation -->
1289 *
1290 * <!-- start release-specific documentation -->
1291 * <span class="ReleaseSpecificDocumentation">
1292 * <B>HSQLDB-Specific Information:</B> <p>
1293 *
1294 * HSQLDB 1.7.1 does not support this feature. <p>
1295 *
1296 * Calling this method always throws a <CODE>SQLException</CODE>,
1297 * stating that the function is not supported. <p>
1298 *
1299 * </span>
1300 * <!-- end release-specific documentation -->
1301 *
1302 * @exception SQLException if a database access error occurs
1303 * @see jdbcStatement#addBatch
1304 * @since JDK 1.2 (JDK 1.1.x developers: read the new overview for
1305 * jdbcPreparedStatement)
1306 */
1307 public void addBatch() throws SQLException {
1308 throw getNotSupported();
1309 }
1310
1311 /**
1312 * <!-- start generic documentation -->
1313 * Sets the designated parameter to the given <code>Reader</code>
1314 * object, which is the given number of characters long.
1315 * When a very large UNICODE value is input to a <code>LONGVARCHAR</code>
1316 * parameter, it may be more practical to send it via a
1317 * <code>java.io.Reader</code> object. The data will be read from the
1318 * stream as needed until end-of-file is reached. The JDBC driver will
1319 * do any necessary conversion from UNICODE to the database char format.
1320 *
1321 * <P><B>Note:</B> This stream object can either be a standard
1322 * Java stream object or your own subclass that implements the
1323 * standard interface. <p>
1324 * <!-- end generic documentation -->
1325 *
1326 * <!-- start release-specific documentation -->
1327 * <span class="ReleaseSpecificDocumentation">
1328 * <B>HSQLDB-Specific Information:</B> <p>
1329 *
1330 * HSQLDB 1.7.0 stores CHARACTER and related SQL types as Unicode so
1331 * this method does not perform any conversion.<p>
1332 *
1333 * </span>
1334 * <!-- end release-specific documentation -->
1335 *
1336 * @param parameterIndex the first parameter is 1, the second is 2, ...
1337 * @param reader the <code>java.io.Reader</code> object that contains the
1338 * Unicode data
1339 * @param length the number of characters in the stream
1340 * @exception SQLException if a database access error occurs
1341 * @since JDK 1.2 (JDK 1.1.x developers: read the new overview for
1342 * jdbcPreparedStatement)
1343 */
1344
1345// fredt@users 20020429 - patch 1.7.0 - method defined
1346// fredt@users 20020627 - patch 574234 by ohioedge@users
1347 public void setCharacterStream(int parameterIndex, java.io.Reader reader,
1348 int length) throws SQLException {
1349
1350 char[] buffer = new char[length];
1351
1352 try {
1353 int result = reader.read(buffer);
1354
1355 if (result == -1) {
1356 throw new IOException();
1357 }
1358 } catch (IOException e) {
1359 throw Trace.error(Trace.TRANSFER_CORRUPTED);
1360 }
1361
1362 setString(parameterIndex, new String(buffer));
1363 }
1364
1365 /**
1366 * <!-- start generic documentation -->
1367 * Sets the designated parameter to the given
1368 * <code>REF(<structured-type>)</code> value.
1369 * The driver converts this to an SQL <code>REF</code> value when it
1370 * sends it to the database. <p>
1371 * <!-- end generic documentation -->
1372 *
1373 * <!-- start release-specific documentation -->
1374 * <span class="ReleaseSpecificDocumentation">
1375 * <B>HSQLDB-Specific Information:</B> <p>
1376 *
1377 * HSQLDB 1.7.1 does not support this feature. <p>
1378 *
1379 * Calling this method always throws a <CODE>SQLException</CODE>,
1380 * stating that the function is not supported. <p>
1381 * </span>
1382 * <!-- end release-specific documentation -->
1383 *
1384 * @param i the first parameter is 1, the second is 2, ...
1385 * @param x an SQL <code>REF</code> value
1386 * @exception SQLException if a database access error occurs
1387 * @since JDK 1.2 (JDK 1.1.x developers: read the new overview for
1388 * jdbcPreparedStatement)
1389 */
1390 public void setRef(int i, Ref x) throws SQLException {
1391 throw getNotSupported();
1392 }
1393
1394 /**
1395 * <!-- start generic documentation -->
1396 * Sets the designated parameter to the given <code>Blob</code> object.
1397 * The driver converts this to an SQL <code>BLOB</code> value when it
1398 * sends it to the database. <p>
1399 * <!-- end generic documentation -->
1400 *
1401 * <!-- start release-specific documentation -->
1402 * <span class="ReleaseSpecificDocumentation">
1403 * <B>HSQLDB-Specific Information:</B> <p>
1404 *
1405 * HSQLDB 1.7.1 does not support this feature. <p>
1406 *
1407 * Calling this method always throws a <CODE>SQLException</CODE>,
1408 * stating that the function is not supported. <p>
1409 *
1410 * </span>
1411 * <!-- end release-specific documentation -->
1412 *
1413 * @param i the first parameter is 1, the second is 2, ...
1414 * @param x a <code>Blob</code> object that maps an SQL <code>BLOB</code>
1415 * value
1416 * @exception SQLException if a database access error occurs
1417 * @since JDK 1.2 (JDK 1.1.x developers: read the new overview for
1418 * jdbcPreparedStatement)
1419 */
1420 public void setBlob(int i, Blob x) throws SQLException {
1421 throw getNotSupported();
1422 }
1423
1424 /**
1425 * <!-- start generic documentation -->
1426 * Sets the designated parameter to the given <code>Clob</code> object.
1427 * The driver converts this to an SQL <code>CLOB</code> value when it
1428 * sends it to the database. <p>
1429 * <!-- end generic documentation -->
1430 *
1431 * <!-- start release-specific documentation -->
1432 * <span class="ReleaseSpecificDocumentation">
1433 * <B>HSQLDB-Specific Information:</B> <p>
1434 *
1435 * HSQLDB 1.7.1 does not support this feature. <p>
1436 *
1437 * Calling this method always throws a <CODE>SQLException</CODE>,
1438 * stating that the function is not supported. <p>
1439 *
1440 * </span>
1441 * <!-- end release-specific documentation -->
1442 *
1443 * @param i the first parameter is 1, the second is 2, ...
1444 * @param x a <code>Clob</code> object that maps an SQL <code>CLOB</code>
1445 * value
1446 * @exception SQLException if a database access error occurs
1447 * @since JDK 1.2 (JDK 1.1.x developers: read the new overview for
1448 * jdbcPreparedStatement)
1449 */
1450 public void setClob(int i, Clob x) throws SQLException {
1451 throw getNotSupported();
1452 }
1453
1454 /**
1455 * <!-- start generic documentation -->
1456 * Sets the designated parameter to the given <code>Array</code> object.
1457 * The driver converts this to an SQL <code>ARRAY</code> value when it
1458 * sends it to the database. <p>
1459 * <!-- end generic documentation -->
1460 *
1461 * <!-- start release-specific documentation -->
1462 * <span class="ReleaseSpecificDocumentation">
1463 * <B>HSQLDB-Specific Information:</B> <p>
1464 *
1465 * HSQLDB 1.7.1 does not support this feature. <p>
1466 *
1467 * Calling this method always throws a <CODE>SQLException</CODE>,
1468 * stating that the function is not supported. <p>
1469 *
1470 * </span>
1471 * <!-- end release-specific documentation -->
1472 *
1473 * @param i the first parameter is 1, the second is 2, ...
1474 * @param x an <code>Array</code> object that maps an SQL <code>ARRAY</code>
1475 * value
1476 * @exception SQLException if a database access error occurs
1477 * @since JDK 1.2 (JDK 1.1.x developers: read the new overview for
1478 * jdbcPreparedStatement)
1479 */
1480 public void setArray(int i, Array x) throws SQLException {
1481 throw getNotSupported();
1482 }
1483
1484 /**
1485 * <!-- start generic documentation -->
1486 * Retrieves a <code>ResultSetMetaData</code> object that contains
1487 * information about the columns of the <code>ResultSet</code> object
1488 * that will be returned when this <code>PreparedStatement</code> object
1489 * is executed.
1490 * <P>
1491 * Because a <code>PreparedStatement</code> object is precompiled, it is
1492 * possible to know about the <code>ResultSet</code> object that it will
1493 * return without having to execute it. Consequently, it is possible
1494 * to invoke the method <code>getMetaData</code> on a
1495 * <code>PreparedStatement</code> object rather than waiting to execute
1496 * it and then invoking the <code>ResultSet.getMetaData</code> method
1497 * on the <code>ResultSet</code> object that is returned.
1498 * <P>
1499 * <B>NOTE:</B> Using this method may be expensive for some drivers due
1500 * to the lack of underlying DBMS support. <p>
1501 * <!-- end generic documentation -->
1502 *
1503 * <!-- start release-specific documentation -->
1504 * <span class="ReleaseSpecificDocumentation">
1505 * <B>HSQLDB-Specific Information:</B> <p>
1506 *
1507 * HSQLDB 1.7.1 does not support this feature. <p>
1508 *
1509 * Calling this method always throws a <CODE>SQLException</CODE>,
1510 * stating that the function is not supported. <p>
1511 *
1512 * </span>
1513 * <!-- end release-specific documentation -->
1514 *
1515 * @return the description of a <code>ResultSet</code> object's columns or
1516 * <code>null</code> if the driver cannot return a
1517