KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mysql > jdbc > PreparedStatement


1 /*
2    Copyright (C) 2002 MySQL AB
3
4       This program is free software; you can redistribute it and/or modify
5       it under the terms of the GNU General Public License as published by
6       the Free Software Foundation; either version 2 of the License, or
7       (at your option) any later version.
8
9       This program is distributed in the hope that it will be useful,
10       but WITHOUT ANY WARRANTY; without even the implied warranty of
11       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12       GNU General Public License for more details.
13
14       You should have received a copy of the GNU General Public License
15       along with this program; if not, write to the Free Software
16       Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18  */

19 package com.mysql.jdbc;
20
21 import java.io.ByteArrayInputStream JavaDoc;
22 import java.io.ByteArrayOutputStream JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.InputStream JavaDoc;
25 import java.io.ObjectOutputStream JavaDoc;
26 import java.io.Reader JavaDoc;
27 import java.io.StringReader JavaDoc;
28 import java.io.UnsupportedEncodingException JavaDoc;
29
30 import java.math.BigDecimal JavaDoc;
31
32 import java.net.URL JavaDoc;
33
34 import java.sql.Array JavaDoc;
35 import java.sql.Clob JavaDoc;
36 import java.sql.ParameterMetaData JavaDoc;
37 import java.sql.Ref JavaDoc;
38 import java.sql.SQLException JavaDoc;
39 import java.sql.Time JavaDoc;
40 import java.sql.Timestamp JavaDoc;
41 import java.sql.Types JavaDoc;
42
43 import java.text.ParsePosition JavaDoc;
44 import java.text.SimpleDateFormat JavaDoc;
45
46 import java.util.ArrayList JavaDoc;
47 import java.util.Calendar JavaDoc;
48 import java.util.TimeZone JavaDoc;
49
50
51 /**
52  * A SQL Statement is pre-compiled and stored in a PreparedStatement object.
53  * This object can then be used to efficiently execute this statement multiple
54  * times.
55  *
56  * <p>
57  * <B>Note:</B> The setXXX methods for setting IN parameter values must specify
58  * types that are compatible with the defined SQL type of the input parameter.
59  * For instance, if the IN parameter has SQL type Integer, then setInt should
60  * be used.
61  * </p>
62  *
63  * <p>
64  * If arbitrary parameter type conversions are required, then the setObject
65  * method should be used with a target SQL type.
66  * </p>
67  *
68  * @author Mark Matthews
69  * @version $Id: PreparedStatement.java,v 1.27.2.33 2004/02/05 15:56:17 mmatthew Exp $
70  *
71  * @see java.sql.ResultSet
72  * @see java.sql.PreparedStatement
73  */

74 public class PreparedStatement extends com.mysql.jdbc.Statement
75     implements java.sql.PreparedStatement JavaDoc {
76     private java.sql.DatabaseMetaData JavaDoc dbmd = null;
77     private ParseInfo parseInfo;
78     private java.sql.ResultSetMetaData JavaDoc pstmtResultMetaData;
79     private SimpleDateFormat JavaDoc tsdf = null;
80     private String JavaDoc originalSql = null;
81     private boolean[] isNull = null;
82     private boolean[] isStream = null;
83     private InputStream JavaDoc[] parameterStreams = null;
84     private byte[][] parameterValues = null;
85     private byte[][] staticSqlStrings = null;
86     private byte[] streamConvertBuf = new byte[4096];
87     private int[] streamLengths = null;
88     private boolean hasLimitClause = false;
89     private boolean isLoadDataQuery = false;
90     private boolean retrieveGeneratedKeys = false;
91     private boolean useTrueBoolean = false;
92     private char firstCharOfStmt = 0;
93
94     /**
95      * Constructor for the PreparedStatement class.
96      *
97      * @param conn the connection creating this statement
98      * @param sql the SQL for this statement
99      * @param catalog the catalog/database this statement should be issued
100      * against
101      *
102      * @throws SQLException if a database error occurs.
103      */

104     public PreparedStatement(Connection conn, String JavaDoc sql, String JavaDoc catalog)
105         throws SQLException JavaDoc {
106         super(conn, catalog);
107
108         if (sql == null) {
109             throw new SQLException JavaDoc("SQL String can not be NULL", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
110         }
111
112         originalSql = sql;
113
114         this.dbmd = this.connection.getMetaData();
115
116         useTrueBoolean = connection.getIO().versionMeetsMinimum(3, 21, 23);
117
118         this.parseInfo = new ParseInfo(sql, this.connection, this.dbmd,
119                 this.charEncoding, this.charConverter);
120
121         initializeFromParseInfo();
122     }
123
124     /**
125      * Creates a new PreparedStatement object.
126      *
127      * @param conn the connection creating this statement
128      * @param sql the SQL for this statement
129      * @param catalog the catalog/database this statement should be issued
130      * against
131      * @param cachedParseInfo already created parseInfo.
132      *
133      * @throws SQLException DOCUMENT ME!
134      */

135     public PreparedStatement(Connection conn, String JavaDoc sql, String JavaDoc catalog,
136         ParseInfo cachedParseInfo) throws SQLException JavaDoc {
137         super(conn, catalog);
138
139         if (sql == null) {
140             throw new SQLException JavaDoc("SQL String can not be NULL", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
141         }
142
143         originalSql = sql;
144
145         this.dbmd = this.connection.getMetaData();
146
147         useTrueBoolean = connection.getIO().versionMeetsMinimum(3, 21, 23);
148
149         this.parseInfo = cachedParseInfo;
150
151         initializeFromParseInfo();
152     }
153
154     /**
155      * JDBC 2.0 Set an Array parameter.
156      *
157      * @param i the first parameter is 1, the second is 2, ...
158      * @param x an object representing an SQL array
159      *
160      * @throws SQLException because this method is not implemented.
161      * @throws NotImplemented DOCUMENT ME!
162      */

163     public void setArray(int i, Array JavaDoc x) throws SQLException JavaDoc {
164         throw new NotImplemented();
165     }
166
167     /**
168      * When a very large ASCII value is input to a LONGVARCHAR parameter, it
169      * may be more practical to send it via a java.io.InputStream. JDBC will
170      * read the data from the stream as needed, until it reaches end-of-file.
171      * The JDBC driver will do any necessary conversion from ASCII to the
172      * database char format.
173      *
174      * <P>
175      * <B>Note:</B> This stream object can either be a standard Java stream
176      * object or your own subclass that implements the standard interface.
177      * </p>
178      *
179      * @param parameterIndex the first parameter is 1...
180      * @param x the parameter value
181      * @param length the number of bytes in the stream
182      *
183      * @exception SQLException if a database access error occurs
184      */

185     public synchronized void setAsciiStream(int parameterIndex, InputStream JavaDoc x,
186         int length) throws SQLException JavaDoc {
187         if (x == null) {
188             setNull(parameterIndex, java.sql.Types.VARCHAR);
189         } else {
190             setBinaryStream(parameterIndex, x, length);
191         }
192     }
193
194     /**
195      * Set a parameter to a java.math.BigDecimal value. The driver converts
196      * this to a SQL NUMERIC value when it sends it to the database.
197      *
198      * @param parameterIndex the first parameter is 1...
199      * @param x the parameter value
200      *
201      * @exception SQLException if a database access error occurs
202      */

203     public void setBigDecimal(int parameterIndex, BigDecimal JavaDoc x)
204         throws SQLException JavaDoc {
205         if (x == null) {
206             setNull(parameterIndex, java.sql.Types.DECIMAL);
207         } else {
208             setInternal(parameterIndex, fixDecimalExponent(x.toString()));
209         }
210     }
211
212     /**
213      * When a very large binary value is input to a LONGVARBINARY parameter, it
214      * may be more practical to send it via a java.io.InputStream. JDBC will
215      * read the data from the stream as needed, until it reaches end-of-file.
216      *
217      * <P>
218      * <B>Note:</B> This stream object can either be a standard Java stream
219      * object or your own subclass that implements the standard interface.
220      * </p>
221      *
222      * @param parameterIndex the first parameter is 1...
223      * @param x the parameter value
224      * @param length the number of bytes to read from the stream (ignored)
225      *
226      * @throws SQLException if a database access error occurs
227      * @throws java.sql.SQLException DOCUMENT ME!
228      */

229     public void setBinaryStream(int parameterIndex, InputStream JavaDoc x, int length)
230         throws SQLException JavaDoc {
231         if (x == null) {
232             setNull(parameterIndex, java.sql.Types.BINARY);
233         } else {
234             if ((parameterIndex < 1)
235                     || (parameterIndex > staticSqlStrings.length)) {
236                 throw new java.sql.SQLException JavaDoc(
237                     "Parameter index out of range (" + parameterIndex + " > "
238                     + staticSqlStrings.length + ")", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
239             }
240
241             parameterStreams[parameterIndex - 1] = x;
242             isStream[parameterIndex - 1] = true;
243             streamLengths[parameterIndex - 1] = length;
244             isNull[parameterIndex - 1] = false;
245         }
246     }
247
248     /**
249      * JDBC 2.0 Set a BLOB parameter.
250      *
251      * @param i the first parameter is 1, the second is 2, ...
252      * @param x an object representing a BLOB
253      *
254      * @throws SQLException if a database error occurs
255      */

256     public void setBlob(int i, java.sql.Blob JavaDoc x) throws SQLException JavaDoc {
257         setBinaryStream(i, x.getBinaryStream(), (int) x.length());
258     }
259
260     /**
261      * Set a parameter to a Java boolean value. The driver converts this to a
262      * SQL BIT value when it sends it to the database.
263      *
264      * @param parameterIndex the first parameter is 1...
265      * @param x the parameter value
266      *
267      * @throws SQLException if a database access error occurs
268      */

269     public void setBoolean(int parameterIndex, boolean x)
270         throws SQLException JavaDoc {
271         if (useTrueBoolean) {
272             setInternal(parameterIndex, x ? "'1'" : "'0'");
273         } else {
274             setInternal(parameterIndex, x ? "'t'" : "'f'");
275         }
276     }
277
278     /**
279      * Set a parameter to a Java byte value. The driver converts this to a SQL
280      * TINYINT value when it sends it to the database.
281      *
282      * @param parameterIndex the first parameter is 1...
283      * @param x the parameter value
284      *
285      * @exception SQLException if a database access error occurs
286      */

287     public void setByte(int parameterIndex, byte x) throws SQLException JavaDoc {
288         setInternal(parameterIndex, String.valueOf(x));
289     }
290
291     /**
292      * Set a parameter to a Java array of bytes. The driver converts this to a
293      * SQL VARBINARY or LONGVARBINARY (depending on the argument's size
294      * relative to the driver's limits on VARBINARYs) when it sends it to the
295      * database.
296      *
297      * @param parameterIndex the first parameter is 1...
298      * @param x the parameter value
299      *
300      * @exception SQLException if a database access error occurs
301      */

302     public void setBytes(int parameterIndex, byte[] x)
303         throws SQLException JavaDoc {
304         if (x == null) {
305             setNull(parameterIndex, java.sql.Types.BINARY);
306         } else {
307             // escape them
308
int numBytes = x.length;
309
310             ByteArrayOutputStream JavaDoc bOut = new ByteArrayOutputStream JavaDoc(numBytes);
311
312             bOut.write('\'');
313
314             for (int i = 0; i < numBytes; ++i) {
315                 byte b = x[i];
316
317                 switch (b) {
318                 case 0: /* Must be escaped for 'mysql' */
319                     bOut.write('\\');
320                     bOut.write('0');
321
322                     break;
323
324                 case '\n': /* Must be escaped for logs */
325                     bOut.write('\\');
326                     bOut.write('n');
327
328                     break;
329
330                 case '\r':
331                     bOut.write('\\');
332                     bOut.write('r');
333
334                     break;
335
336                 case '\\':
337                     bOut.write('\\');
338                     bOut.write('\\');
339
340                     break;
341
342                 case '\'':
343                     bOut.write('\\');
344                     bOut.write('\'');
345
346                     break;
347
348                 case '"': /* Better safe than sorry */
349                     bOut.write('\\');
350                     bOut.write('"');
351
352                     break;
353
354                 case '\032': /* This gives problems on Win32 */
355                     bOut.write('\\');
356                     bOut.write('Z');
357
358                     break;
359
360                 default:
361                     bOut.write(b);
362                 }
363             }
364
365             bOut.write('\'');
366
367             setInternal(parameterIndex, bOut.toByteArray());
368         }
369     }
370
371     /**
372      * JDBC 2.0 When a very large UNICODE value is input to a LONGVARCHAR
373      * parameter, it may be more practical to send it via a java.io.Reader.
374      * JDBC will read the data from the stream as needed, until it reaches
375      * end-of-file. The JDBC driver will do any necessary conversion from
376      * UNICODE to the database char format.
377      *
378      * <P>
379      * <B>Note:</B> This stream object can either be a standard Java stream
380      * object or your own subclass that implements the standard interface.
381      * </p>
382      *
383      * @param parameterIndex the first parameter is 1, the second is 2, ...
384      * @param reader the java reader which contains the UNICODE data
385      * @param length the number of characters in the stream
386      *
387      * @throws SQLException if a database-access error occurs.
388      */

389     public void setCharacterStream(int parameterIndex, java.io.Reader JavaDoc reader,
390         int length) throws SQLException JavaDoc {
391         try {
392             if (reader == null) {
393                 setNull(parameterIndex, Types.LONGVARCHAR);
394             } else {
395                 char[] c = null;
396                 int len = 0;
397
398                 boolean useLength = this.connection.useStreamLengthsInPrepStmts();
399
400                 if (useLength && (length != -1)) {
401                     c = new char[length];
402
403                     int numCharsRead = readFully(reader, c, length); // blocks until all read
404

405                     setString(parameterIndex, new String JavaDoc(c, 0, numCharsRead));
406                 } else {
407                     c = new char[4096];
408
409                     StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
410
411                     while ((len = reader.read(c)) != -1) {
412                         buf.append(c, 0, len);
413                     }
414
415                     setString(parameterIndex, buf.toString());
416                 }
417             }
418         } catch (java.io.IOException JavaDoc ioEx) {
419             throw new SQLException JavaDoc(ioEx.toString(), SQLError.SQL_STATE_GENERAL_ERROR);
420         }
421     }
422
423     /**
424      * JDBC 2.0 Set a CLOB parameter.
425      *
426      * @param i the first parameter is 1, the second is 2, ...
427      * @param x an object representing a CLOB
428      *
429      * @throws SQLException if a database error occurs
430      */

431     public void setClob(int i, Clob x) throws SQLException JavaDoc {
432         setString(i, x.getSubString(1L, (int) x.length()));
433     }
434
435     /**
436      * Set a parameter to a java.sql.Date value. The driver converts this to a
437      * SQL DATE value when it sends it to the database.
438      *
439      * @param parameterIndex the first parameter is 1...
440      * @param x the parameter value
441      *
442      * @exception SQLException if a database access error occurs
443      */

444     public void setDate(int parameterIndex, java.sql.Date JavaDoc x)
445         throws SQLException JavaDoc {
446         if (x == null) {
447             setNull(parameterIndex, java.sql.Types.DATE);
448         } else {
449             // FIXME: Have instance version of this, problem as it's
450
// not thread-safe :(
451
SimpleDateFormat JavaDoc dateFormatter = new SimpleDateFormat JavaDoc(
452                     "''yyyy-MM-dd''");
453             setInternal(parameterIndex, dateFormatter.format(x));
454         }
455     }
456
457     /**
458      * Set a parameter to a java.sql.Date value. The driver converts this to a
459      * SQL DATE value when it sends it to the database.
460      *
461      * @param parameterIndex the first parameter is 1, the second is 2, ...
462      * @param x the parameter value
463      * @param cal the calendar to interpret the date with
464      *
465      * @throws SQLException if a database-access error occurs.
466      */

467     public void setDate(int parameterIndex, java.sql.Date JavaDoc x, Calendar JavaDoc cal)
468         throws SQLException JavaDoc {
469         setDate(parameterIndex, x);
470     }
471
472     /**
473      * Set a parameter to a Java double value. The driver converts this to a
474      * SQL DOUBLE value when it sends it to the database
475      *
476      * @param parameterIndex the first parameter is 1...
477      * @param x the parameter value
478      *
479      * @throws SQLException if a database access error occurs
480      */

481     public void setDouble(int parameterIndex, double x)
482         throws SQLException JavaDoc {
483         setInternal(parameterIndex, fixDecimalExponent(String.valueOf(x)));
484     }
485
486     /**
487      * Set a parameter to a Java float value. The driver converts this to a
488      * SQL FLOAT value when it sends it to the database.
489      *
490      * @param parameterIndex the first parameter is 1...
491      * @param x the parameter value
492      *
493      * @throws SQLException if a database access error occurs
494      */

495     public void setFloat(int parameterIndex, float x) throws SQLException JavaDoc {
496         setInternal(parameterIndex, fixDecimalExponent(String.valueOf(x)));
497     }
498
499     /**
500      * Set a parameter to a Java int value. The driver converts this to a SQL
501      * INTEGER value when it sends it to the database.
502      *
503      * @param parameterIndex the first parameter is 1...
504      * @param x the parameter value
505      *
506      * @throws SQLException if a database access error occurs
507      */

508     public void setInt(int parameterIndex, int x) throws SQLException JavaDoc {
509         setInternal(parameterIndex, String.valueOf(x));
510     }
511
512     /**
513      * Set a parameter to a Java long value. The driver converts this to a SQL
514      * BIGINT value when it sends it to the database.
515      *
516      * @param parameterIndex the first parameter is 1...
517      * @param x the parameter value
518      *
519      * @throws SQLException if a database access error occurs
520      */

521     public void setLong(int parameterIndex, long x) throws SQLException JavaDoc {
522         setInternal(parameterIndex, String.valueOf(x));
523     }
524
525     /**
526      * The number, types and properties of a ResultSet's columns are provided
527      * by the getMetaData method.
528      *
529      * @return the description of a ResultSet's columns
530      *
531      * @throws SQLException if a database-access error occurs.
532      */

533     public synchronized java.sql.ResultSetMetaData JavaDoc getMetaData() throws SQLException JavaDoc {
534         PreparedStatement mdStmt = null;
535         java.sql.ResultSet JavaDoc mdRs = null;
536
537         if (this.pstmtResultMetaData == null) {
538             try {
539                 mdStmt = new PreparedStatement(this.connection,
540                         this.originalSql, this.currentCatalog, this.parseInfo);
541
542                 mdStmt.setMaxRows(0);
543
544                 int paramCount = this.parameterValues.length;
545
546                 for (int i = 1; i <= paramCount; i++) {
547                     mdStmt.setString(i, "");
548                 }
549
550                 boolean hadResults = mdStmt.execute();
551
552                 if (hadResults) {
553                     mdRs = mdStmt.getResultSet();
554
555                     this.pstmtResultMetaData = mdRs.getMetaData();
556                 } else {
557                     this.pstmtResultMetaData = new ResultSetMetaData(new Field[0]);
558                 }
559             } finally {
560                 SQLException JavaDoc sqlExRethrow = null;
561
562                 if (mdRs != null) {
563                     try {
564                         mdRs.close();
565                     } catch (SQLException JavaDoc sqlEx) {
566                         sqlExRethrow = sqlEx;
567                     }
568
569                     mdRs = null;
570                 }
571
572                 if (mdStmt != null) {
573                     try {
574                         mdStmt.close();
575                     } catch (SQLException JavaDoc sqlEx) {
576                         sqlExRethrow = sqlEx;
577                     }
578
579                     mdStmt = null;
580                 }
581
582                 if (sqlExRethrow != null) {
583                     throw sqlExRethrow;
584                 }
585             }
586         }
587
588         return this.pstmtResultMetaData;
589     }
590
591     /**
592      * Set a parameter to SQL NULL
593      *
594      * <p>
595      * <B>Note:</B> You must specify the parameters SQL type (although MySQL
596      * ignores it)
597      * </p>
598      *
599      * @param parameterIndex the first parameter is 1, etc...
600      * @param sqlType the SQL type code defined in java.sql.Types
601      *
602      * @throws SQLException if a database access error occurs
603      */

604     public void setNull(int parameterIndex, int sqlType)
605         throws SQLException JavaDoc {
606         setInternal(parameterIndex, "null");
607         isNull[parameterIndex - 1] = true;
608     }
609
610     //--------------------------JDBC 2.0-----------------------------
611

612     /**
613      * Set a parameter to SQL NULL.
614      *
615      * <P>
616      * <B>Note:</B> You must specify the parameter's SQL type.
617      * </p>
618      *
619      * @param parameterIndex the first parameter is 1, the second is 2, ...
620      * @param sqlType SQL type code defined by java.sql.Types
621      * @param arg argument parameters for null
622      *
623      * @throws SQLException if a database-access error occurs.
624      */

625     public void setNull(int parameterIndex, int sqlType, String JavaDoc arg)
626         throws SQLException JavaDoc {
627         setNull(parameterIndex, sqlType);
628     }
629
630     /**
631      * Set the value of a parameter using an object; use the java.lang
632      * equivalent objects for integral values.
633      *
634      * <P>
635      * The given Java object will be converted to the targetSqlType before
636      * being sent to the database.
637      * </p>
638      *
639      * <P>
640      * note that this method may be used to pass database-specific abstract
641      * data types. This is done by using a Driver-specific Java type and
642      * using a targetSqlType of java.sql.Types.OTHER
643      * </p>
644      *
645      * @param parameterIndex the first parameter is 1...
646      * @param parameterObj the object containing the input parameter value
647      * @param targetSqlType The SQL type to be send to the database
648      * @param scale For java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types
649      * this is the number of digits after the decimal. For all other
650      * types this value will be ignored.
651      *
652      * @throws SQLException if a database access error occurs
653      * @throws java.sql.SQLException DOCUMENT ME!
654      */

655     public void setObject(int parameterIndex, Object JavaDoc parameterObj,
656         int targetSqlType, int scale) throws SQLException JavaDoc {
657         if (parameterObj == null) {
658             setNull(parameterIndex, java.sql.Types.OTHER);
659         } else {
660             try {
661                 switch (targetSqlType) {
662                 case Types.BIT:
663                 case Types.TINYINT:
664                 case Types.SMALLINT:
665                 case Types.INTEGER:
666                 case Types.BIGINT:
667                 case Types.REAL:
668                 case Types.FLOAT:
669                 case Types.DOUBLE:
670                 case Types.DECIMAL:
671                 case Types.NUMERIC:
672
673                     Number JavaDoc parameterAsNum;
674
675                     if (parameterObj instanceof Boolean JavaDoc) {
676                         parameterAsNum = ((Boolean JavaDoc) parameterObj).booleanValue()
677                             ? new Integer JavaDoc(1) : new Integer JavaDoc(0);
678                     } else if (parameterObj instanceof String JavaDoc) {
679                         switch (targetSqlType) {
680                         case Types.BIT:
681                             parameterAsNum = (Boolean.getBoolean((String JavaDoc) parameterObj)
682                                 ? new Integer JavaDoc("1") : new Integer JavaDoc("0"));
683
684                             break;
685
686                         case Types.TINYINT:
687                         case Types.SMALLINT:
688                         case Types.INTEGER:
689                             parameterAsNum = Integer.valueOf((String JavaDoc) parameterObj);
690
691                             break;
692
693                         case Types.BIGINT:
694                             parameterAsNum = Long.valueOf((String JavaDoc) parameterObj);
695
696                             break;
697
698                         case Types.REAL:
699                             parameterAsNum = Float.valueOf((String JavaDoc) parameterObj);
700
701                             break;
702
703                         case Types.FLOAT:
704                         case Types.DOUBLE:
705                             parameterAsNum = Double.valueOf((String JavaDoc) parameterObj);
706
707                             break;
708
709                         case Types.DECIMAL:
710                         case Types.NUMERIC:default:
711                             parameterAsNum = new java.math.BigDecimal JavaDoc((String JavaDoc) parameterObj);
712                         }
713                     } else {
714                         parameterAsNum = (Number JavaDoc) parameterObj;
715                     }
716
717                     switch (targetSqlType) {
718                     case Types.BIT:
719                     case Types.TINYINT:
720                     case Types.SMALLINT:
721                     case Types.INTEGER:
722                         setInt(parameterIndex, parameterAsNum.intValue());
723
724                         break;
725
726                     case Types.BIGINT:
727                         setLong(parameterIndex, parameterAsNum.longValue());
728
729                         break;
730
731                     case Types.REAL:
732                         setFloat(parameterIndex, parameterAsNum.floatValue());
733
734                         break;
735
736                     case Types.FLOAT:
737                     case Types.DOUBLE:
738                         setDouble(parameterIndex, parameterAsNum.doubleValue());
739
740                         break;
741
742                     case Types.DECIMAL:
743                     case Types.NUMERIC:default:
744
745                         if (parameterAsNum instanceof java.math.BigDecimal JavaDoc) {
746                             setBigDecimal(parameterIndex,
747                                 (java.math.BigDecimal JavaDoc) parameterAsNum);
748                         } else if (parameterAsNum instanceof java.math.BigInteger JavaDoc) {
749                             setBigDecimal(parameterIndex,
750                                 new java.math.BigDecimal JavaDoc(
751                                     (java.math.BigInteger JavaDoc) parameterAsNum, scale));
752                         } else {
753                             setBigDecimal(parameterIndex,
754                                 new java.math.BigDecimal JavaDoc(
755                                     parameterAsNum.doubleValue()));
756                         }
757
758                         break;
759                     }
760
761                     break;
762
763                 case Types.CHAR:
764                 case Types.VARCHAR:
765                 case Types.LONGVARCHAR:
766                     setString(parameterIndex, parameterObj.toString());
767
768                     break;
769
770                 case Types.CLOB:
771
772                     if (parameterObj instanceof java.sql.Clob JavaDoc) {
773                         setClob(parameterIndex, (java.sql.Clob JavaDoc) parameterObj);
774                     } else {
775                         setString(parameterIndex, parameterObj.toString());
776                     }
777
778                     break;
779
780                 case Types.BINARY:
781                 case Types.VARBINARY:
782                 case Types.LONGVARBINARY:
783                 case Types.BLOB:
784
785                     if (parameterObj instanceof byte[]) {
786                         setBytes(parameterIndex, (byte[]) parameterObj);
787                     } else if (parameterObj instanceof java.sql.Blob JavaDoc) {
788                         setBlob(parameterIndex, (java.sql.Blob JavaDoc) parameterObj);
789                     } else {
790                         setBytes(parameterIndex,
791                             StringUtils.getBytes(parameterObj.toString(),
792                                 this.charConverter, this.charEncoding));
793                     }
794
795                     break;
796
797                 case Types.DATE:
798                 case Types.TIMESTAMP:
799
800                     java.util.Date JavaDoc parameterAsDate;
801
802                     if (parameterObj instanceof String