KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > driver > CallableStatement


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Copyright (C) 2005 Continuent, Inc.
6  * Contact: sequoia@continuent.org
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  * Initial developer(s): Emmanuel Cecchet.
21  * Contributor(s): ______________________________________.
22  */

23
24 package org.continuent.sequoia.driver;
25
26 import java.io.ByteArrayOutputStream JavaDoc;
27 import java.io.IOException JavaDoc;
28 import java.io.InputStream JavaDoc;
29 import java.io.ObjectOutputStream JavaDoc;
30 import java.io.Reader JavaDoc;
31 import java.io.Serializable JavaDoc;
32 import java.math.BigDecimal JavaDoc;
33 import java.net.URL JavaDoc;
34 import java.sql.Array JavaDoc;
35 import java.sql.BatchUpdateException JavaDoc;
36 import java.sql.Blob JavaDoc;
37 import java.sql.Clob JavaDoc;
38 import java.sql.Date JavaDoc;
39 import java.sql.Ref JavaDoc;
40 import java.sql.ResultSet JavaDoc;
41 import java.sql.SQLException JavaDoc;
42 import java.sql.SQLWarning JavaDoc;
43 import java.sql.Time JavaDoc;
44 import java.sql.Timestamp JavaDoc;
45 import java.sql.Types JavaDoc;
46 import java.util.Calendar JavaDoc;
47 import java.util.HashMap JavaDoc;
48 import java.util.Iterator JavaDoc;
49 import java.util.LinkedList JavaDoc;
50 import java.util.List JavaDoc;
51 import java.util.Map JavaDoc;
52
53 import org.continuent.sequoia.common.exceptions.NotImplementedException;
54 import org.continuent.sequoia.common.protocol.PreparedStatementSerializationConstants;
55 import org.continuent.sequoia.common.sql.Request;
56 import org.continuent.sequoia.common.sql.RequestWithResultSetParameters;
57 import org.continuent.sequoia.common.sql.filters.AbstractBlobFilter;
58 import org.continuent.sequoia.common.util.Strings;
59
60 /**
61  * This class is used to execute SQL stored procedures. The JDBC API provides a
62  * stored procedure SQL escape syntax that allows stored procedures to be called
63  * in a standard way for all RDBMSs. The syntax accepted by this implementation
64  * is as follows:
65  *
66  * <pre>
67  * {call &lt;procedure-name&gt;[&lt;arg1&gt;,&lt;arg2&gt;, ...]}
68  * </pre>
69  *
70  * or (since Sequoia 2.7)
71  *
72  * <pre>
73  * {?= call &lt;procedure-name&gt;[&lt;arg1&gt;,&lt;arg2&gt;, ...]}
74  * </pre>
75  *
76  * Parameters are referred to sequentially, by number, with the first parameter
77  * being 1. IN parameter values are set using the <code>set</code> methods
78  * inherited from {@link PreparedStatement}.
79  * <p>
80  * OUT and JDBC 3 named parameters are implemented in this class.
81  * <p>
82  * A <code>CallableStatement</code> can return one {@link DriverResultSet}
83  * object or multiple <code>ResultSet</code> objects. Multiple
84  * <code>ResultSet</code> objects are handled using operations inherited from
85  * {@link Statement}.
86  *
87  * @see org.continuent.sequoia.driver.Connection#prepareCall(String)
88  * @see DriverResultSet
89  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
90  * @version 1.0
91  */

92 public class CallableStatement extends PreparedStatement
93     implements
94       java.sql.CallableStatement JavaDoc
95 {
96   // Values returned by out parameters
97
private HashMap JavaDoc outParameters = null;
98   // Out and named parameter types set by the application
99
private HashMap JavaDoc outAndNamedParameterTypes = null;
100   // Named parameter returned values
101
private HashMap JavaDoc namedParameterValues = null;
102   private int lastOutParameterIndex = -1;
103
104   /**
105    * <code>CallableStatements</code> syntax is {call procedure_name[(?, ?,
106    * ...)]}. Note that {? = call ...} is not supported by this implementation.
107    *
108    * @param connection the instanatiating connection
109    * @param sql the SQL statement with ? for IN markers
110    * @param driver the Driver used to create connections
111    */

112   public CallableStatement(Connection connection, String JavaDoc sql, Driver driver)
113   {
114     super(connection, sql, driver);
115   }
116
117   /**
118    * Add names parameters at the end of regular parameters.
119    *
120    * @see PreparedStatement#compileParameters(boolean)
121    */

122   protected synchronized String JavaDoc compileParameters() throws SQLException JavaDoc
123   {
124     // Call PreparedStatement.compileParameters()
125
String JavaDoc parameters = super.compileParameters(true);
126
127     if (outAndNamedParameterTypes == null)
128       return parameters;
129
130     // Append named parameters but reuse sbuf set by super.compileParameters()
131
// for more efficiency
132
for (Iterator JavaDoc iter = outAndNamedParameterTypes.values().iterator(); iter
133         .hasNext();)
134     {
135       String JavaDoc namedParam = (String JavaDoc) iter.next();
136       sbuf.append(namedParam);
137     }
138     return sbuf.toString();
139   }
140
141   /**
142    * @see org.continuent.sequoia.driver.PreparedStatement#execute()
143    */

144   public boolean execute() throws SQLException JavaDoc
145   {
146     if (isClosed())
147     {
148       throw new SQLException JavaDoc("Unable to execute query on a closed statement");
149     }
150     RequestWithResultSetParameters proc = new RequestWithResultSetParameters(
151         sql, compileParameters(), escapeProcessing, timeout);
152     setReadRequestParameters(proc);
153     ResultAndWarnings result = connection.callableStatementExecute(proc);
154     warnings = result.getStatementWarnings();
155     List JavaDoc resultWithParameters = result.getResultList();
156     resultList = (LinkedList JavaDoc) resultWithParameters.get(0);
157     resultListIterator = resultList.iterator();
158     outParameters = (HashMap JavaDoc) resultWithParameters.get(1);
159     namedParameterValues = (HashMap JavaDoc) resultWithParameters.get(2);
160
161     return getMoreResults();
162   }
163
164   /**
165    * Execute a batch of commands
166    *
167    * @return an array containing update count that corresponding to the commands
168    * that executed successfully
169    * @exception BatchUpdateException if an error occurs on one statement (the
170    * number of updated rows for the successfully executed
171    * statements can be found in
172    * BatchUpdateException.getUpdateCounts())
173    */

174   public int[] executeBatch() throws BatchUpdateException JavaDoc
175   {
176     if (batch == null || batch.isEmpty())
177       return new int[0];
178
179     int size = batch.size();
180     int[] nbsRowsUpdated = new int[size];
181     int i = 0;
182     // must keep warning in a separate place otherwise they will be erased at
183
// each call to executeUpdate()
184
SQLWarning JavaDoc allWarnings = null;
185     try
186     {
187       for (i = 0; i < size; i++)
188       {
189         BatchElement be = (BatchElement) batch.elementAt(i);
190         Request proc = new Request(be.getSqlTemplate(), be.getParameters(),
191             escapeProcessing, timeout);
192
193         ResultAndWarnings result = connection
194             .callableStatementExecuteUpdate(proc);
195         if (result.getStatementWarnings() != null)
196           addWarningTo(result.getStatementWarnings(), allWarnings);
197         List JavaDoc resultWithParameters = result.getResultList();
198         nbsRowsUpdated[i] = ((Integer JavaDoc) resultWithParameters.get(0)).intValue();
199         // Not sure what to do with OUT and named parameters. Just keep them in
200
// case someone wants to access the ones returned by the last executed
201
// statement.
202
outParameters = (HashMap JavaDoc) resultWithParameters.get(1);
203         namedParameterValues = (HashMap JavaDoc) resultWithParameters.get(2);
204       }
205       // make one chain with all generated warnings
206
warnings = allWarnings;
207       return nbsRowsUpdated;
208     }
209     catch (SQLException JavaDoc e)
210     {
211       String JavaDoc message = "Batch failed for request " + i + ": "
212           + ((BatchElement) batch.elementAt(i)).getSqlTemplate() + " (" + e
213           + ")";
214
215       // shrink the returned array
216
int[] updateCounts = new int[i];
217       System.arraycopy(nbsRowsUpdated, 0, updateCounts, 0, i);
218
219       throw new BatchUpdateException JavaDoc(message, updateCounts);
220     }
221     finally
222     {
223       batch.removeAllElements();
224     }
225   }
226
227   /**
228    * @see org.continuent.sequoia.driver.PreparedStatement#executeQuery()
229    */

230   public ResultSet JavaDoc executeQuery() throws SQLException JavaDoc
231   {
232     if (isClosed())
233     {
234       throw new SQLException JavaDoc("Unable to execute query on a closed statement");
235     }
236     updateCount = -1; // invalidate the last write result
237
if (result != null)
238     { // Discard the previous result
239
result.close();
240       result = null;
241     }
242
243     RequestWithResultSetParameters proc = new RequestWithResultSetParameters(
244         sql, compileParameters(), escapeProcessing, timeout);
245     setReadRequestParameters(proc);
246     ResultAndWarnings res = connection.callableStatementExecuteQuery(proc);
247     warnings = res.getStatementWarnings();
248     List JavaDoc resultWithParameters = res.getResultList();
249     result = (ResultSet JavaDoc) resultWithParameters.get(0);
250     outParameters = (HashMap JavaDoc) resultWithParameters.get(1);
251     namedParameterValues = (HashMap JavaDoc) resultWithParameters.get(2);
252     if (result instanceof DriverResultSet)
253       ((DriverResultSet) result).setStatement(this);
254     return result;
255   }
256
257   /**
258    * @see org.continuent.sequoia.driver.PreparedStatement#executeUpdate()
259    */

260   public int executeUpdate() throws SQLException JavaDoc
261   {
262     if (isClosed())
263     {
264       throw new SQLException JavaDoc("Unable to execute query on a closed statement");
265     }
266     if (result != null)
267     { // Discard the previous result
268
result.close();
269       result = null;
270     }
271     Request proc = new Request(sql, compileParameters(), escapeProcessing,
272         timeout);
273     ResultAndWarnings result = connection.callableStatementExecuteUpdate(proc);
274     this.warnings = result.getStatementWarnings();
275     List JavaDoc resultWithParameters = result.getResultList();
276     updateCount = ((Integer JavaDoc) resultWithParameters.get(0)).intValue();
277     outParameters = (HashMap JavaDoc) resultWithParameters.get(1);
278     namedParameterValues = (HashMap JavaDoc) resultWithParameters.get(2);
279
280     return updateCount;
281   }
282
283   /**
284    * Registers the OUT parameter in ordinal position <code>parameterIndex</code>
285    * to the JDBC type <code>sqlType</code>. All OUT parameters must be
286    * registered before a stored procedure is executed.
287    * <p>
288    * The JDBC type specified by <code>sqlType</code> for an OUT parameter
289    * determines the Java type that must be used in the <code>get</code> method
290    * to read the value of that parameter.
291    * <p>
292    * If the JDBC type expected to be returned to this output parameter is
293    * specific to this particular database, <code>sqlType</code> should be
294    * <code>java.sql.Types.OTHER</code>. The method {@link #getObject(int)}
295    * retrieves the value.
296    *
297    * @param parameterIndex the first parameter is 1, the second is 2, and so on
298    * @param sqlType the JDBC type code defined by <code>java.sql.Types</code>.
299    * If the parameter is of JDBC type <code>NUMERIC</code> or
300    * <code>DECIMAL</code>, the version of
301    * <code>registerOutParameter</code> that accepts a scale value
302    * should be used.
303    * @exception SQLException if a database access error occurs
304    * @see java.sql.Types
305    */

306   public void registerOutParameter(int parameterIndex, int sqlType)
307       throws SQLException JavaDoc
308   {
309     setOutParameterWithTag(String.valueOf(parameterIndex),
310         PreparedStatementSerializationConstants.REGISTER_OUT_PARAMETER, String
311             .valueOf(sqlType));
312   }
313
314   /**
315    * Registers the parameter in ordinal position <code>parameterIndex</code>
316    * to be of JDBC type <code>sqlType</code>. This method must be called
317    * before a stored procedure is executed.
318    * <p>
319    * The JDBC type specified by <code>sqlType</code> for an OUT parameter
320    * determines the Java type that must be used in the <code>get</code> method
321    * to read the value of that parameter.
322    * <p>
323    * This version of <code>registerOutParameter</code> should be used when the
324    * parameter is of JDBC type <code>NUMERIC</code> or <code>DECIMAL</code>.
325    *
326    * @param parameterIndex the first parameter is 1, the second is 2, and so on
327    * @param sqlType the SQL type code defined by <code>java.sql.Types</code>.
328    * @param scale the desired number of digits to the right of the decimal
329    * point. It must be greater than or equal to zero.
330    * @exception SQLException if a database access error occurs
331    * @see java.sql.Types
332    */

333   public void registerOutParameter(int parameterIndex, int sqlType, int scale)
334       throws SQLException JavaDoc
335   {
336     setOutParameterWithTag(
337         String.valueOf(parameterIndex),
338         PreparedStatementSerializationConstants.REGISTER_OUT_PARAMETER_WITH_SCALE,
339         sqlType + "," + scale);
340   }
341
342   /**
343    * Registers the designated output parameter. This version of the method
344    * <code>registerOutParameter</code> should be used for a user-defined or
345    * <code>REF</code> output parameter. Examples of user-defined types
346    * include: <code>STRUCT</code>,<code>DISTINCT</code>,
347    * <code>JAVA_OBJECT</code>, and named array types.
348    * <p>
349    * Before executing a stored procedure call, you must explicitly call
350    * <code>registerOutParameter</code> to register the type from
351    * <code>java.sql.Types</code> for each OUT parameter. For a user-defined
352    * parameter, the fully-qualified SQL type name of the parameter should also
353    * be given, while a <code>REF</code> parameter requires that the
354    * fully-qualified type name of the referenced type be given. A JDBC driver
355    * that does not need the type code and type name information may ignore it.
356    * To be portable, however, applications should always provide these values
357    * for user-defined and <code>REF</code> parameters.
358    * <p>
359    * Although it is intended for user-defined and <code>REF</code> parameters,
360    * this method may be used to register a parameter of any JDBC type. If the
361    * parameter does not have a user-defined or <code>REF</code> type, the
362    * <i>typeName </i> parameter is ignored.
363    * <p>
364    * <b>Note: </b> When reading the value of an out parameter, you must use the
365    * getter method whose Java type corresponds to the parameter's registered SQL
366    * type.
367    *
368    * @param paramIndex the first parameter is 1, the second is 2,...
369    * @param sqlType a value from {@link java.sql.Types}
370    * @param typeName the fully-qualified name of an SQL structured type
371    * @exception SQLException if a database access error occurs
372    * @see java.sql.Types
373    * @since 1.2
374    */

375   public void registerOutParameter(int paramIndex, int sqlType, String JavaDoc typeName)
376       throws SQLException JavaDoc
377   {
378     setOutParameterWithTag(
379         String.valueOf(paramIndex),
380         PreparedStatementSerializationConstants.REGISTER_OUT_PARAMETER_WITH_NAME,
381         sqlType + "," + typeName);
382   }
383
384   /**
385    * Get the Java SQL type of an OUT parameter. Throws an SQLException if the
386    * parameter was not an OUT parameter.
387    *
388    * @param parameterIndex parameter index
389    * @return Java SQL type
390    * @throws SQLException if the parameter is not an out parameter or an invalid
391    * parameter
392    */

393   private int getOutParameterType(int parameterIndex) throws SQLException JavaDoc
394   {
395     lastOutParameterIndex = -1;
396
397     if (outParameters == null)
398       throw new SQLException JavaDoc("No OUT parameter has been returned");
399
400     lastOutParameterIndex = parameterIndex;
401
402     String JavaDoc type = (String JavaDoc) outAndNamedParameterTypes.get(Integer
403         .toString(parameterIndex));
404     if (type != null)
405     {
406       int typeStart = PreparedStatementSerializationConstants.START_PARAM_TAG
407           .length();
408       String JavaDoc paramType = type.substring(typeStart, typeStart
409           + PreparedStatementSerializationConstants.BOOLEAN_TAG.length());
410       String JavaDoc paramValue = type.substring(typeStart
411           + PreparedStatementSerializationConstants.BOOLEAN_TAG.length(), type
412           .indexOf(PreparedStatementSerializationConstants.END_PARAM_TAG));
413
414       // paramType is a NAMED_PARAMETER_TAG
415

416       // Value is composed of: paramName,paramTypeparamValue
417
// paramName is equal to parameterIndex (just ignore it)
418
// paramTypeparamValue should be the out parameter and its value
419
int comma = paramValue.indexOf(",");
420       paramValue = paramValue.substring(comma + 1);
421
422       if (paramType
423           .startsWith(PreparedStatementSerializationConstants.REGISTER_OUT_PARAMETER))
424         return Integer.parseInt(paramValue);
425       if (paramType
426           .startsWith(PreparedStatementSerializationConstants.REGISTER_OUT_PARAMETER_WITH_NAME))
427         return Integer.parseInt(paramValue
428             .substring(0, paramValue.indexOf(',')));
429       if (paramType
430           .startsWith(PreparedStatementSerializationConstants.REGISTER_OUT_PARAMETER_WITH_SCALE))
431         return Integer.parseInt(paramValue
432             .substring(0, paramValue.indexOf(',')));
433     }
434     throw new SQLException JavaDoc("Parameter " + parameterIndex
435         + " is not a registered OUT parameter");
436   }
437
438   /**
439    * Retrieves whether the last OUT parameter read had the value of SQL
440    * <code>NULL</code>. Note that this method should be called only after
441    * calling a getter method; otherwise, there is no value to use in determining
442    * whether it is <code>null</code> or not.
443    *
444    * @return <code>true</code> if the last parameter read was SQL
445    * <code>NULL</code>;<code>false</code> otherwise
446    * @exception SQLException if a database access error occurs
447    */

448   public boolean wasNull() throws SQLException JavaDoc
449   {
450     if (lastOutParameterIndex == -1)
451       return false;
452     return (outParameters.get(new Integer JavaDoc(lastOutParameterIndex)) == null);
453   }
454
455   /**
456    * Retrieves the value of the designated JDBC <code>CHAR</code>,
457    * <code>VARCHAR</code>, or <code>LONGVARCHAR</code> parameter as a
458    * <code>String</code> in the Java programming language.
459    * <p>
460    * For the fixed-length type JDBC <code>CHAR</code>, the
461    * <code>String</code> object returned has exactly the same value the JDBC
462    * <code>CHAR</code> value had in the database, including any padding added
463    * by the database.
464    *
465    * @param parameterIndex the first parameter is 1, the second is 2, and so on
466    * @return the parameter value. If the value is SQL <code>NULL</code>, the
467    * result is <code>null</code>.
468    * @exception SQLException if a database access error occurs
469    * @see #setString
470    */

471   public String JavaDoc getString(int parameterIndex) throws SQLException JavaDoc
472   {
473     int type = getOutParameterType(parameterIndex);
474     switch (type)
475     {
476       case Types.CHAR :
477       case Types.VARCHAR :
478       case Types.LONGVARCHAR :
479         return (String JavaDoc) outParameters.get(new Integer JavaDoc(parameterIndex));
480       default :
481         throw new SQLException JavaDoc("Cannot convert OUT parameter of type " + type
482             + " to the requested type.");
483     }
484   }
485
486   /**
487    * Retrieves the value of the designated JDBC <code>BIT</code> parameter as
488    * a <code>boolean</code> in the Java programming language.
489    *
490    * @param parameterIndex the first parameter is 1, the second is 2, and so on
491    * @return the parameter value. If the value is SQL <code>NULL</code>, the
492    * result is <code>false</code>.
493    * @exception SQLException if a database access error occurs
494    * @see #setBoolean
495    */

496   public boolean getBoolean(int parameterIndex) throws SQLException JavaDoc
497   {
498     int type = getOutParameterType(parameterIndex);
499     switch (type)
500     {
501       case Types.BIT :
502         Boolean JavaDoc b = (Boolean JavaDoc) outParameters.get(new Integer JavaDoc(parameterIndex));
503         if (b == null)
504           return false;
505         else
506           return b.booleanValue();
507       default :
508         throw new SQLException JavaDoc("Cannot convert OUT parameter of type " + type
509             + " to the requested type.");
510     }
511   }
512
513   /**
514    * Retrieves the value of the designated JDBC <code>TINYINT</code> parameter
515    * as a <code>byte</code> in the Java programming language.
516    *
517    * @param parameterIndex the first parameter is 1, the second is 2, and so on
518    * @return the parameter value. If the value is SQL <code>NULL</code>, the
519    * result is <code>0</code>.
520    * @exception SQLException if a database access error occurs
521    * @see #setByte
522    */

523   public byte getByte(int parameterIndex) throws SQLException JavaDoc
524   {
525     int type = getOutParameterType(parameterIndex);
526     switch (type)
527     {
528       case Types.TINYINT :
529         Number JavaDoc b = (Number JavaDoc) outParameters.get(new Integer JavaDoc(parameterIndex));
530         if (b == null)
531           return 0;
532         else
533           return b.byteValue();
534       default :
535         throw new SQLException JavaDoc("Cannot convert OUT parameter of type " + type
536             + " to the requested type.");
537     }
538   }
539
540   /**
541    * Retrieves the value of the designated JDBC <code>SMALLINT</code>
542    * parameter as a <code>short</code> in the Java programming language.
543    *
544    * @param parameterIndex the first parameter is 1, the second is 2, and so on
545    * @return the parameter value. If the value is SQL <code>NULL</code>, the
546    * result is <code>0</code>.
547    * @exception SQLException if a database access error occurs
548    * @see #setShort
549    */

550   public short getShort(int parameterIndex) throws SQLException JavaDoc
551   {
552     int type = getOutParameterType(parameterIndex);
553     switch (type)
554     {
555       case Types.SMALLINT :
556         Number JavaDoc s = (Number JavaDoc) outParameters.get(new Integer JavaDoc(parameterIndex));
557         if (s == null)
558           return 0;
559         else
560           return s.shortValue();
561       default :
562         throw new SQLException JavaDoc("Cannot convert OUT parameter of type " + type
563             + " to the requested type.");
564     }
565   }
566
567   /**
568    * Retrieves the value of the designated JDBC <code>INTEGER</code> parameter
569    * as an <code>int</code> in the Java programming language.
570    *
571    * @param parameterIndex the first parameter is 1, the second is 2, and so on
572    * @return the parameter value. If the value is SQL <code>NULL</code>, the
573    * result is <code>0</code>.
574    * @exception SQLException if a database access error occurs
575    * @see #setInt
576    */

577   public int getInt(int parameterIndex) throws SQLException JavaDoc
578   {
579     int type = getOutParameterType(parameterIndex);
580     switch (type)
581     {
582       case Types.INTEGER :
583         Integer JavaDoc i = (Integer JavaDoc) outParameters.get(new Integer JavaDoc(parameterIndex));
584         if (i == null)
585           return 0;
586         else
587           return i.intValue();
588       default :
589         throw new SQLException JavaDoc("Cannot convert OUT parameter of type " + type
590             + " to the requested type.");
591     }
592   }
593
594   /**
595    * Retrieves the value of the designated JDBC <code>BIGINT</code> parameter
596    * as a <code>long</code> in the Java programming language.
597    *
598    * @param parameterIndex the first parameter is 1, the second is 2, and so on
599    * @return the parameter value. If the value is SQL <code>NULL</code>, the
600    * result is <code>0</code>.
601    * @exception SQLException if a database access error occurs
602    * @see #setLong
603    */

604   public long getLong(int parameterIndex) throws SQLException JavaDoc
605   {
606     int type = getOutParameterType(parameterIndex);
607     switch (type)
608     {
609       case Types.BIGINT :
610         Long JavaDoc l = (Long JavaDoc) outParameters.get(new Integer JavaDoc(parameterIndex));
611         if (l == null)
612           return 0;
613         else
614           return l.longValue();
615       default :
616         throw new SQLException JavaDoc("Cannot convert OUT parameter of type " + type
617             + " to the requested type.");
618     }
619   }
620
621   /**
622    * Retrieves the value of the designated JDBC <code>FLOAT</code> parameter
623    * as a <code>float</code> in the Java programming language.
624    *
625    * @param parameterIndex the first parameter is 1, the second is 2, and so on
626    * @return the parameter value. If the value is SQL <code>NULL</code>, the
627    * result is <code>0</code>.
628    * @exception SQLException if a database access error occurs
629    * @see #setFloat
630    */

631   public float getFloat(int parameterIndex) throws SQLException JavaDoc
632   {
633     int type = getOutParameterType(parameterIndex);
634     switch (type)
635     {
636       case Types.FLOAT :
637       case Types.REAL :
638         Float JavaDoc f = (Float JavaDoc) outParameters.get(new Integer JavaDoc(parameterIndex));
639         if (f == null)
640           return 0;
641         else
642           return f.floatValue();
643       default :
644         throw new SQLException JavaDoc("Cannot convert OUT parameter of type " + type
645             + " to the requested type.");
646     }
647   }
648
649   /**
650    * Retrieves the value of the designated JDBC <code>DOUBLE</code> parameter
651    * as a <code>double</code> in the Java programming language.
652    *
653    * @param parameterIndex the first parameter is 1, the second is 2, and so on
654    * @return the parameter value. If the value is SQL <code>NULL</code>, the
655    * result is <code>0</code>.
656    * @exception SQLException if a database access error occurs
657    * @see #setDouble
658    */

659   public double getDouble(int parameterIndex) throws SQLException JavaDoc
660   {
661     int type = getOutParameterType(parameterIndex);
662     switch (type)
663     {
664       case Types.DOUBLE :
665       case Types.FLOAT :
666         Double JavaDoc d = (Double JavaDoc) outParameters.get(new Integer JavaDoc(parameterIndex));
667         if (d == null)
668           return 0;
669         else
670           return d.doubleValue();
671       default :
672         throw new SQLException JavaDoc("Cannot convert OUT parameter of type " + type
673             + " to the requested type.");
674     }
675   }
676
677   /**
678    * Retrieves the value of the designated JDBC <code>NUMERIC</code> parameter
679    * as a <code>java.math.BigDecimal</code> object with <i>scale </i> digits
680    * to the right of the decimal point.
681    *
682    * @param parameterIndex the first parameter is 1, the second is 2, and so on
683    * @param scale the number of digits to the right of the decimal point
684    * @return the parameter value. If the value is SQL <code>NULL</code>, the
685    * result is <code>null</code>.
686    * @exception SQLException if a database access error occurs
687    * @deprecated use <code>getBigDecimal(int parameterIndex)</code> or
688    * <code>getBigDecimal(String parameterName)</code>
689    * @see #setBigDecimal
690    */

691   public BigDecimal JavaDoc getBigDecimal(int parameterIndex, int scale)
692       throws SQLException JavaDoc
693   {
694     return getBigDecimal(parameterIndex);
695   }
696
697   /**
698    * Retrieves the value of the designated JDBC <code>BINARY</code> or
699    * <code>VARBINARY</code> parameter as an array of <code>byte</code>
700    * values in the Java programming language.
701    *
702    * @param parameterIndex the first parameter is 1, the second is 2, and so on
703    * @return the parameter value. If the value is SQL <code>NULL</code>, the
704    * result is <code>null</code>.
705    * @exception SQLException if a database access error occurs
706    * @see #setBytes
707    */

708   public byte[] getBytes(int parameterIndex) throws SQLException JavaDoc
709   {
710     int type = getOutParameterType(parameterIndex);
711     switch (type)
712     {
713       case Types.BINARY :
714         return (byte[]) outParameters.get(new Integer JavaDoc(parameterIndex));
715       default :
716         throw new SQLException JavaDoc("Cannot convert OUT parameter of type " + type
717             + " to the requested type.");
718     }
719
720   }
721
722   /**
723    * Retrieves the value of the designated JDBC <code>DATE</code> parameter as
724    * a <code>java.sql.Date</code> object.
725    *
726    * @param parameterIndex the first parameter is 1, the second is 2, and so on
727    * @return the parameter value. If the value is SQL <code>NULL</code>, the
728    * result is <code>null</code>.
729    * @exception SQLException if a database access error occurs
730    * @see #setDate(String, Date)
731    */

732   public Date JavaDoc getDate(int parameterIndex) throws SQLException JavaDoc
733   {
734     int type = getOutParameterType(parameterIndex);
735     switch (type)
736     {
737       case Types.DATE :
738         return (Date JavaDoc) outParameters.get(new Integer JavaDoc(parameterIndex));
739       default :
740         throw new SQLException JavaDoc("Cannot convert OUT parameter of type " + type
741             + " to the requested type.");
742     }
743   }
744
745   /**
746    * Retrieves the value of the designated JDBC <code>TIME</code> parameter as
747    * a <code>java.sql.Time</code> object.
748    *
749    * @param parameterIndex the first parameter is 1, the second is 2, and so on
750    * @return the parameter value. If the value is SQL <code>NULL</code>, the
751    * result is <code>null</code>.
752    * @exception SQLException if a database access error occurs
753    * @see #setTime(String, Time)
754    */

755   public Time JavaDoc getTime(int parameterIndex) throws SQLException JavaDoc
756   {
757     int type = getOutParameterType(parameterIndex);
758     switch (type)
759     {
760       case Types.TIME :
761         return (Time JavaDoc) outParameters.get(new Integer JavaDoc(parameterIndex));
762       default :
763         throw new SQLException JavaDoc("Cannot convert OUT parameter of type " + type
764             + " to the requested type.");
765     }
766   }
767
768   /**
769    * Retrieves the value of the designated JDBC <code>TIMESTAMP</code>
770    * parameter as a <code>java.sql.Timestamp</code> object.
771    *
772    * @param parameterIndex the first parameter is 1, the second is 2, and so on
773    * @return the parameter value. If the value is SQL <code>NULL</code>, the
774    * result is <code>null</code>.
775    * @exception SQLException if a database access error occurs
776    * @see #setTimestamp(String, Timestamp)
777    */

778   public Timestamp JavaDoc getTimestamp(int parameterIndex) throws SQLException JavaDoc
779   {
780     int type = getOutParameterType(parameterIndex);
781     switch (type)
782     {
783       case Types.TIMESTAMP :
784         return (Timestamp JavaDoc) outParameters.get(new Integer JavaDoc(parameterIndex));
785       default :
786         throw new SQLException JavaDoc("Cannot convert OUT parameter of type " + type
787             + " to the requested type.");
788     }
789   }
790
791   // ----------------------------------------------------------------------
792
// Advanced features:
793

794   /**
795    * Retrieves the value of the designated parameter as an <code>Object</code>
796    * in the Java programming language. If the value is an SQL <code>NULL</code>,
797    * the driver returns a Java <code>null</code>.
798    * <p>
799    * This method returns a Java object whose type corresponds to the JDBC type
800    * that was registered for this parameter using the method
801    * <code>registerOutParameter</code>. By registering the target JDBC type
802    * as <code>java.sql.Types.OTHER</code>, this method can be used to read
803    * database-specific abstract data types.
804    *
805    * @param parameterIndex the first parameter is 1, the second is 2, and so on
806    * @return A <code>java.lang.Object</code> holding the OUT parameter value
807    * @exception SQLException if a database access error occurs
808    * @see java.sql.Types
809    * @see #setObject(String, Object)
810    */

811   public Object JavaDoc getObject(int parameterIndex) throws SQLException JavaDoc
812   {
813     // Check type first (throw an exception if invalid)
814
getOutParameterType(parameterIndex);
815     return outParameters.get(new Integer JavaDoc(parameterIndex));
816   }
817
818   // --------------------------JDBC 2.0-----------------------------
819

820   /**
821    * Retrieves the value of the designated JDBC <code>NUMERIC</code> parameter
822    * as a <code>java.math.BigDecimal</code> object with as many digits to the
823    * right of the decimal point as the value contains.
824    *
825    * @param parameterIndex the first parameter is 1, the second is 2, and so on
826    * @return the parameter value in full precision. If the value is SQL
827    * <code>NULL</code>, the result is <code>null</code>.
828    * @exception SQLException if a database access error occurs
829    * @see #setBigDecimal
830    * @since 1.2
831    */

832   public BigDecimal JavaDoc getBigDecimal(int parameterIndex) throws SQLException JavaDoc
833   {
834     int type = getOutParameterType(parameterIndex);
835     switch (type)
836     {
837       case Types.NUMERIC :
838       case Types.DECIMAL :
839         return (BigDecimal JavaDoc) outParameters.get(new Integer JavaDoc(parameterIndex));
840       default :
841         throw new SQLException JavaDoc("Cannot convert OUT parameter of type " + type
842             + " to the requested type.");
843     }
844   }
845
846   /**
847    * Returns an object representing the value of OUT parameter <code>i</code>
848    * and uses <code>map</code> for the custom mapping of the parameter value.
849    * <p>
850    * This method returns a Java object whose type corresponds to the JDBC type
851    * that was registered for this parameter using the method
852    * <code>registerOutParameter</code>. By registering the target JDBC type
853    * as <code>java.sql.Types.OTHER</code>, this method can be used to read
854    * database-specific abstract data types.
855    *
856    * @param i the first parameter is 1, the second is 2, and so on
857    * @param map the mapping from SQL type names to Java classes
858    * @return a <code>java.lang.Object</code> holding the OUT parameter value
859    * @exception SQLException if a database access error occurs
860    * @see #setObject(String, Object)
861    * @since 1.2
862    */

863   public Object JavaDoc getObject(int i, Map JavaDoc map) throws SQLException JavaDoc
864   {
865     throw new NotImplementedException("getObject");
866   }
867
868   /**
869    * Retrieves the value of the designated JDBC
870    * <code>REF(&lt;structured-type&gt;)</code> parameter as a <code>Ref</code>
871    * object in the Java programming language.
872    *
873    * @param parameterIndex the first parameter is 1, the second is 2, and so on
874    * @return the parameter value as a <code>Ref</code> object in the Java
875    * programming language. If the value was SQL <code>NULL</code>,
876    * the value <code>null</code> is returned.
877    * @exception SQLException if a database access error occurs
878    * @since 1.2
879    */

880   public Ref JavaDoc getRef(int parameterIndex) throws SQLException JavaDoc
881   {
882     int type = getOutParameterType(parameterIndex);
883     switch (type)
884     {
885       case Types.REF :
886         return (Ref JavaDoc) outParameters.get(new Integer JavaDoc(parameterIndex));
887       default :
888         throw new SQLException JavaDoc("Cannot convert OUT parameter of type " + type
889             + " to the requested type.");
890     }
891   }
892
893   /**
894    * Retrieves the value of the designated JDBC <code>BLOB</code> parameter as
895    * a {@link Blob}object in the Java programming language.
896    *
897    * @param i the first parameter is 1, the second is 2, and so on
898    * @return the parameter value as a <code>Blob</code> object in the Java
899    * programming language. If the value was SQL <code>NULL</code>,
900    * the value <code>null</code> is returned.
901    * @exception SQLException if a database access error occurs
902    * @since 1.2
903    */

904   public Blob JavaDoc getBlob(int i) throws SQLException JavaDoc
905   {
906     int type = getOutParameterType(i);
907     switch (type)
908     {
909       case Types.BLOB :
910         return (Blob JavaDoc) outParameters.get(new Integer JavaDoc(i));
911       default :
912         throw new SQLException JavaDoc("Cannot convert OUT parameter of type " + type
913             + " to the requested type.");
914     }
915   }
916
917   /**
918    * Retrieves the value of the designated JDBC <code>CLOB</code> parameter as
919    * a <code>Clob</code> object in the Java programming language.
920    *
921    * @param i the first parameter is 1, the second is 2, and so on
922    * @return the parameter value as a <code>Clob</code> object in the Java
923    * programming language. If the value was SQL <code>NULL</code>,
924    * the value <code>null</code> is returned.
925    * @exception SQLException if a database access error occurs
926    * @since 1.2
927    */

928   public Clob JavaDoc getClob(int i) throws SQLException JavaDoc
929   {
930     int type = getOutParameterType(i);
931     switch (type)
932     {
933       case Types.CLOB :
934         return (Clob JavaDoc) outParameters.get(new Integer JavaDoc(i));
935       default :
936         throw new SQLException JavaDoc("Cannot convert OUT parameter of type " + type
937             + " to the requested type.");
938     }
939   }
940
941   /**
942    * Retrieves the value of the designated JDBC <code>ARRAY</code> parameter
943    * as an {@link Array}object in the Java programming language.
944    *
945    * @param i the first parameter is 1, the second is 2, and so on
946    * @return the parameter value as an <code>Array</code> object in the Java
947    * programming language. If the value was SQL <code>NULL</code>,
948    * the value <code>null</code> is returned.
949    * @exception SQLException if a database access error occurs
950    * @since 1.2
951    */

952   public Array JavaDoc getArray(int i) throws SQLException JavaDoc
953   {
954     int type = getOutParameterType(i);
955     switch (type)
956     {
957       case Types.ARRAY :
958         return (Array JavaDoc) outParameters.get(new Integer JavaDoc(i));
959       default :
960         throw new SQLException JavaDoc("Cannot convert OUT parameter of type " + type
961             + " to the requested type.");
962     }
963   }
964
965   /**
966    * Retrieves the value of the designated JDBC <code>DATE</code> parameter as
967    * a <code>java.sql.Date</code> object, using the given
968    * <code>Calendar</code> object to construct the date. With a
969    * <code>Calendar</code> object, the driver can calculate the date taking
970    * into account a custom timezone and locale. If no <code>Calendar</code>
971    * object is specified, the driver uses the default timezone and locale.
972    *
973    * @param parameterIndex the first parameter is 1, the second is 2, and so on
974    * @param cal the <code>Calendar</code> object the driver will use to
975    * construct the date
976    * @return the parameter value. If the value is SQL <code>NULL</code>, the
977    * result is <code>null</code>.
978    * @exception SQLException if a database access error occurs
979    * @see #setDate(String, Date)
980    * @since 1.2
981    */

982   public Date JavaDoc getDate(int parameterIndex, Calendar JavaDoc cal) throws SQLException JavaDoc
983   {
984     return getDate(parameterIndex);
985   }
986
987   /**
988    * Retrieves the value of the designated JDBC <code>TIME</code> parameter as
989    * a <code>java.sql.Time</code> object, using the given
990    * <code>Calendar</code> object to construct the time. With a
991    * <code>Calendar</code> object, the driver can calculate the time taking
992    * into account a custom timezone and locale. If no <code>Calendar</code>
993    * object is specified, the driver uses the default timezone and locale.
994    *
995    * @param parameterIndex the first parameter is 1, the second is 2, and so on
996    * @param cal the <code>Calendar</code> object the driver will use to
997    * construct the time
998    * @return the parameter value; if the value is SQL <code>NULL</code>, the
999    * result is <code>null</code>.
1000   * @exception SQLException if a database access error occurs
1001   * @see #setTime(String, Time)
1002   * @since 1.2
1003   */

1004  public Time JavaDoc getTime(int parameterIndex, Calendar JavaDoc cal) throws SQLException JavaDoc
1005  {
1006    return getTime(parameterIndex);
1007  }
1008
1009  /**
1010   * Retrieves the value of the designated JDBC <code>TIMESTAMP</code>
1011   * parameter as a <code>java.sql.Timestamp</code> object, using the given
1012   * <code>Calendar</code> object to construct the <code>Timestamp</code>
1013   * object. With a <code>Calendar</code> object, the driver can calculate the
1014   * timestamp taking into account a custom timezone and locale. If no
1015   * <code>Calendar</code> object is specified, the driver uses the default
1016   * timezone and locale.
1017   *
1018   * @param parameterIndex the first parameter is 1, the second is 2, and so on
1019   * @param cal the <code>Calendar</code> object the driver will use to
1020   * construct the timestamp
1021   * @return the parameter value. If the value is SQL <code>NULL</code>, the
1022   * result is <code>null</code>.
1023   * @exception SQLException if a database access error occurs
1024   * @see #setTimestamp(String, Timestamp)
1025   * @since 1.2
1026   */

1027  public Timestamp JavaDoc getTimestamp(int parameterIndex, Calendar JavaDoc cal)
1028      throws SQLException JavaDoc
1029  {
1030    return getTimestamp(parameterIndex);
1031  }
1032
1033  /**
1034   * Retrieves the value of the designated JDBC <code>DATALINK</code>
1035   * parameter as a <code>java.net.URL</code> object.
1036   *
1037   * @param parameterIndex the first parameter is 1, the second is 2,...
1038   * @return a <code>java.net.URL</code> object that represents the JDBC
1039   * <code>DATALINK</code> value used as the designated parameter
1040   * @exception SQLException if a database access error occurs, or if the URL
1041   * being returned is not a valid URL on the Java platform
1042   * @see #setURL
1043   * @since 1.4
1044   */

1045  public URL JavaDoc getURL(int parameterIndex) throws SQLException JavaDoc
1046  {
1047    int type = getOutParameterType(parameterIndex);
1048    switch (type)
1049    {
1050      case Types.DATALINK :
1051        return (URL JavaDoc) outParameters.get(new Integer JavaDoc(parameterIndex));
1052      default :
1053        throw new SQLException JavaDoc("Cannot convert OUT parameter of type " + type
1054            + " to the requested type.");
1055    }
1056  }
1057
1058  /**
1059   * Registers the OUT parameter named <code>parameterName</code> to the JDBC
1060   * type <code>sqlType</code>. All OUT parameters must be registered before
1061   * a stored procedure is executed.
1062   * <p>
1063   * The JDBC type specified by <code>sqlType</code> for an OUT parameter
1064   * determines the Java type that must be used in the <code>get</code> method
1065   * to read the value of that parameter.
1066   * <p>
1067   * If the JDBC type expected to be returned to this output parameter is
1068   * specific to this particular database, <code>sqlType</code> should be
1069   * <code>java.sql.Types.OTHER</code>. The method {@link #getObject(String)}
1070   * retrieves the value.
1071   *
1072   * @param parameterName the name of the parameter
1073   * @param sqlType the JDBC type code defined by <code>java.sql.Types</code>.
1074   * If the parameter is of JDBC type <code>NUMERIC</code> or
1075   * <code>DECIMAL</code>, the version of
1076   * <code>registerOutParameter</code> that accepts a scale value
1077   * should be used.
1078   * @exception SQLException if a database access error occurs
1079   * @since 1.4
1080   * @see java.sql.Types
1081   */

1082  public void registerOutParameter(String JavaDoc parameterName, int sqlType)
1083      throws SQLException JavaDoc
1084  {
1085    setOutParameterWithTag(parameterName,
1086        PreparedStatementSerializationConstants.REGISTER_OUT_PARAMETER, String
1087            .valueOf(sqlType));
1088  }
1089
1090  /**
1091   * Registers the parameter named <code>parameterName</code> to be of JDBC
1092   * type <code>sqlType</code>. This method must be called before a stored
1093   * procedure is executed.
1094   * <p>
1095   * The JDBC type specified by <code>sqlType</code> for an OUT parameter
1096   * determines the Java type that must be used in the <code>get</code> method
1097   * to read the value of that parameter.
1098   * <p>
1099   * This version of <code>registerOutParameter</code> should be used when the
1100   * parameter is of JDBC type <code>NUMERIC</code> or <code>DECIMAL</code>.
1101   *
1102   * @param parameterName the name of the parameter
1103   * @param sqlType SQL type code defined by <code>java.sql.Types</code>.
1104   * @param scale the desired number of digits to the right of the decimal
1105   * point. It must be greater than or equal to zero.
1106   * @exception SQLException if a database access error occurs
1107   * @since 1.4
1108   * @see java.sql.Types
1109   */

1110  public void registerOutParameter(String JavaDoc parameterName, int sqlType, int scale)
1111      throws SQLException JavaDoc
1112  {
1113    setOutParameterWithTag(
1114        parameterName,
1115        PreparedStatementSerializationConstants.REGISTER_OUT_PARAMETER_WITH_SCALE,
1116        String.valueOf(sqlType) + "," + scale);
1117  }
1118
1119  /**
1120   * Registers the designated output parameter. This version of the method
1121   * <code>registerOutParameter</code> should be used for a user-named or REF
1122   * output parameter. Examples of user-named types include: STRUCT, DISTINCT,
1123   * JAVA_OBJECT, and named array types.
1124   * <p>
1125   * Before executing a stored procedure call, you must explicitly call
1126   * <code>registerOutParameter</code> to register the type from
1127   * <code>java.sql.Types</code> for each OUT parameter. For a user-named
1128   * parameter the fully-qualified SQL type name of the parameter should also be
1129   * given, while a REF parameter requires that the fully-qualified type name of
1130   * the referenced type be given. A JDBC driver that does not need the type
1131   * code and type name information may ignore it. To be portable, however,
1132   * applications should always provide these values for user-named and REF
1133   * parameters.
1134   * <p>
1135   * Although it is intended for user-named and REF parameters, this method may
1136   * be used to register a parameter of any JDBC type. If the parameter does not
1137   * have a user-named or REF type, the typeName parameter is ignored.
1138   * <p>
1139   * <b>Note: </b> When reading the value of an out parameter, you must use the
1140   * <code>getXXX</code> method whose Java type XXX corresponds to the
1141   * parameter's registered SQL type.
1142   *
1143   * @param parameterName the name of the parameter
1144   * @param sqlType a value from {@link java.sql.Types}
1145   * @param typeName the fully-qualified name of an SQL structured type
1146   * @exception SQLException if a database access error occurs
1147   * @see java.sql.Types
1148   * @since 1.4
1149   */

1150  public void registerOutParameter(String JavaDoc parameterName, int sqlType,
1151      String JavaDoc typeName) throws SQLException JavaDoc
1152  {
1153    setOutParameterWithTag(
1154        parameterName,
1155        PreparedStatementSerializationConstants.REGISTER_OUT_PARAMETER_WITH_NAME,
1156        String.valueOf(sqlType) + "," + typeName);
1157  }
1158
1159  /**
1160   * Stores an out parameter and its type as a <em>quoted</em> String, so the
1161   * controller can decode them back.
1162   *
1163   * @param paramName the name of the parameter (index must be converted to
1164   * String)
1165   * @param typeTag type of the parameter
1166   * @param paramValue the parameter string to be stored
1167   */

1168  private void setOutParameterWithTag(String JavaDoc paramName, String JavaDoc typeTag,
1169      String JavaDoc paramValue)
1170  {
1171    if (outAndNamedParameterTypes == null)
1172      outAndNamedParameterTypes = new HashMap JavaDoc();
1173
1174    // insert TAGS so the controller can parse and "unset" the request
1175
outAndNamedParameterTypes.put(paramName,
1176        PreparedStatementSerializationConstants.START_PARAM_TAG + typeTag
1177            + paramName + "," + paramValue
1178            + PreparedStatementSerializationConstants.END_PARAM_TAG);
1179  }
1180
1181  /**
1182   * Stores a named parameter and its type as a <em>quoted</em> String, so the
1183   * controller can decode them back.
1184   *
1185   * @param paramName the name of the parameter
1186   * @param typeTag type of the parameter
1187   * @param param the parameter string to be stored
1188   */

1189  private void setNamedParameterWithTag(String JavaDoc paramName, String JavaDoc typeTag,
1190      String JavaDoc param)
1191  {
1192    if (outAndNamedParameterTypes == null)
1193      outAndNamedParameterTypes = new HashMap JavaDoc();
1194
1195    // insert TAGS so the controller can parse and "unset" the request.
1196
outAndNamedParameterTypes.put(paramName,
1197        PreparedStatementSerializationConstants.START_PARAM_TAG
1198            + PreparedStatementSerializationConstants.NAMED_PARAMETER_TAG
1199            + paramName
1200            + ","
1201            + typeTag
1202            + Strings.replace(param,
1203                PreparedStatementSerializationConstants.TAG_MARKER,
1204                PreparedStatementSerializationConstants.TAG_MARKER_ESCAPE)
1205            + PreparedStatementSerializationConstants.END_PARAM_TAG);
1206  }
1207
1208  /**
1209   * Sets the designated parameter to the given <code>java.net.URL</code>
1210   * object. The driver converts this to an SQL <code>DATALINK</code> value
1211   * when it sends it to the database.
1212   *
1213   * @param parameterName the name of the parameter
1214   * @param url the parameter value
1215   * @exception SQLException if a database access error occurs, or if a URL is
1216   * malformed
1217   * @see #getURL(String)
1218   * @since 1.4
1219   */

1220  public void setURL(String JavaDoc parameterName, URL JavaDoc url) throws SQLException JavaDoc
1221  {
1222    if (url == null)
1223      setNamedParameterWithTag(parameterName,
1224          PreparedStatementSerializationConstants.URL_TAG,
1225          PreparedStatementSerializationConstants.NULL_VALUE);
1226    else
1227      setNamedParameterWithTag(parameterName,
1228          PreparedStatementSerializationConstants.URL_TAG, url.toString());
1229  }
1230
1231  /**
1232   * Sets the designated parameter to SQL <code>NULL</code>.
1233   * <p>
1234   * <b>Note: </b> you must specify the parameter's SQL type.
1235   *
1236   * @param parameterName the name of the parameter
1237   * @param sqlType the SQL type code defined in <code>java.sql.Types</code>
1238   * @exception SQLException if a database access error occurs
1239   * @since 1.4
1240   */

1241  public void setNull(String JavaDoc parameterName, int sqlType) throws SQLException JavaDoc
1242  {
1243    setNamedParameterWithTag(parameterName,
1244        PreparedStatementSerializationConstants.NULL_VALUE, String
1245            .valueOf(sqlType));
1246  }
1247
1248  /**
1249   * Sets the designated parameter to the given Java <code>boolean</code>
1250   * value. The driver converts this to an SQL <code>BIT</code> value when it
1251   * sends it to the database.
1252   *
1253   * @param parameterName the name of the parameter
1254   * @param x the parameter value
1255   * @exception SQLException if a database access error occurs
1256   * @see #getBoolean(String)
1257   * @since 1.4
1258   */

1259  public void setBoolean(String JavaDoc parameterName, boolean x) throws SQLException JavaDoc
1260  {
1261    setNamedParameterWithTag(parameterName,
1262        PreparedStatementSerializationConstants.BOOLEAN_TAG, String.valueOf(x));
1263  }
1264
1265  /**
1266   * Sets the designated parameter to the given Java <code>byte</code> value.
1267   * The driver converts this to an SQL <code>TINYINT</code> value when it
1268   * sends it to the database.
1269   *
1270   * @param parameterName the name of the parameter
1271   * @param x the parameter value
1272   * @exception SQLException if a database access error occurs
1273   * @see #getByte(String)
1274   * @since 1.4
1275   */

1276  public void setByte(String JavaDoc parameterName, byte x) throws SQLException JavaDoc
1277  {
1278    setNamedParameterWithTag(parameterName,
1279        PreparedStatementSerializationConstants.BYTE_TAG, Integer.toString(x));
1280  }
1281
1282  /**
1283   * Sets the designated parameter to the given Java <code>short</code> value.
1284   * The driver converts this to an SQL <code>SMALLINT</code> value when it
1285   * sends it to the database.
1286   *
1287   * @param parameterName the name of the parameter
1288   * @param x the parameter value
1289   * @exception SQLException if a database access error occurs
1290   * @see #getShort(String)
1291   * @since 1.4
1292   */

1293  public void setShort(String JavaDoc parameterName, short x) throws SQLException JavaDoc
1294  {
1295    setNamedParameterWithTag(parameterName,
1296        PreparedStatementSerializationConstants.SHORT_TAG, Integer.toString(x));
1297  }
1298
1299  /**
1300   * Sets the designated parameter to the given Java <code>int</code> value.
1301   * The driver converts this to an SQL <code>INTEGER</code> value when it
1302   * sends it to the database.
1303   *
1304   * @param parameterName the name of the parameter
1305   * @param x the parameter value
1306   * @exception SQLException if a database access error occurs
1307   * @see #getInt(String)
1308   * @since 1.4
1309   */

1310  public void setInt(String JavaDoc parameterName, int x) throws SQLException JavaDoc
1311  {
1312    setNamedParameterWithTag(parameterName,
1313        PreparedStatementSerializationConstants.INTEGER_TAG, Integer
1314            .toString(x));
1315  }
1316
1317  /**
1318   * Sets the designated parameter to the given Java <code>long</code> value.
1319   * The driver converts this to an SQL <code>BIGINT</code> value when it
1320   * sends it to the database.
1321   *
1322   * @param parameterName the name of the parameter
1323   * @param x the parameter value
1324   * @exception SQLException if a database access error occurs
1325   * @see #getLong(String)
1326   * @since 1.4
1327   */

1328  public void setLong(String JavaDoc parameterName, long x) throws SQLException JavaDoc
1329  {
1330    setNamedParameterWithTag(parameterName,
1331        PreparedStatementSerializationConstants.LONG_TAG, Long.toString(x));
1332  }
1333
1334  /**
1335   * Sets the designated parameter to the given Java <code>float</code> value.
1336   * The driver converts this to an SQL <code>FLOAT</code> value when it sends
1337   * it to the database.
1338   *
1339   * @param parameterName the name of the parameter
1340   * @param x the parameter value
1341   * @exception SQLException if a database access error occurs
1342   * @see #getFloat(String)
1343   * @since 1.4
1344   */

1345  public void setFloat(String JavaDoc parameterName, float x) throws SQLException JavaDoc
1346  {
1347    setNamedParameterWithTag(parameterName,
1348        PreparedStatementSerializationConstants.FLOAT_TAG, Float.toString(x));
1349  }
1350
1351  /**
1352   * Sets the designated parameter to the given Java <code>double</code>
1353   * value. The driver converts this to an SQL <code>DOUBLE</code> value when
1354   * it sends it to the database.
1355   *
1356   * @param parameterName the name of the parameter
1357   * @param x the parameter value
1358   * @exception SQLException if a database access error occurs
1359   * @see #getDouble(String)
1360   * @since 1.4
1361   */

1362  public void setDouble(String JavaDoc parameterName, double x) throws SQLException JavaDoc
1363  {
1364    setNamedParameterWithTag(parameterName,
1365        PreparedStatementSerializationConstants.DOUBLE_TAG, Double.toString(x));
1366  }
1367
1368  /**
1369   * Sets the designated parameter to the given
1370   * <code>java.math.BigDecimal</code> value. The driver converts this to an
1371   * SQL <code>NUMERIC</code> value when it sends it to the database.
1372   *
1373   * @param parameterName the name of the parameter
1374   * @param x the parameter value
1375   * @exception SQLException if a database access error occurs
1376   * @see #getBigDecimal(String)
1377   * @since 1.4
1378   */

1379  public void setBigDecimal(String JavaDoc parameterName, BigDecimal JavaDoc x)
1380      throws SQLException JavaDoc
1381  {
1382    if (x == null)
1383      setNamedParameterWithTag(parameterName,
1384          PreparedStatementSerializationConstants.BIG_DECIMAL_TAG,
1385          PreparedStatementSerializationConstants.NULL_VALUE);
1386    else
1387      setNamedParameterWithTag(parameterName,
1388          PreparedStatementSerializationConstants.BIG_DECIMAL_TAG, x.toString());
1389  }
1390
1391  /**
1392   * Sets the designated parameter to the given Java <code>String</code>
1393   * value. The driver converts this to an SQL <code>VARCHAR</code> or
1394   * <code>LONGVARCHAR</code> value (depending on the argument's size relative
1395   * to the driver's limits on <code>VARCHAR</code> values) when it sends it
1396   * to the database.
1397   *
1398   * @param parameterName the name of the parameter
1399   * @param x the parameter value
1400   * @exception SQLException if a database access error occurs
1401   * @see #getString(String)
1402   * @since 1.4
1403   */

1404  public void setString(String JavaDoc parameterName, String JavaDoc x) throws SQLException JavaDoc
1405  {
1406    if (x == null)
1407      setNamedParameterWithTag(parameterName,
1408          PreparedStatementSerializationConstants.STRING_TAG,
1409          PreparedStatementSerializationConstants.NULL_VALUE);
1410    else
1411    {
1412      if (PreparedStatementSerializationConstants.NULL_VALUE.equals(x))
1413      { // Someone is trying to set a String that matches our NULL tag, a real
1414
// bad luck, use our special NULL_STRING_TAG!
1415
setNamedParameterWithTag(parameterName,
1416            PreparedStatementSerializationConstants.NULL_STRING_TAG, x);
1417      }
1418      else
1419      { // No escape processing is needed for queries not being parsed into
1420
// statements.
1421
setNamedParameterWithTag(parameterName,
1422            PreparedStatementSerializationConstants.STRING_TAG, x);
1423      }
1424    }
1425  }
1426
1427  /**
1428   * Sets the designated parameter to the given Java array of bytes. The driver
1429   * converts this to an SQL <code>VARBINARY</code> or
1430   * <code>LONGVARBINARY</code> (depending on the argument's size relative to
1431   * the driver's limits on <code>VARBINARY</code> values) when it sends it to
1432   * the database.
1433   *
1434   * @param parameterName the name of the parameter
1435   * @param x the parameter value
1436   * @exception SQLException if a database access error occurs
1437   * @see #getBytes(String)
1438   * @since 1.4
1439   */

1440  public void setBytes(String JavaDoc parameterName, byte[] x) throws SQLException JavaDoc
1441  {
1442    try
1443    {
1444      /**
1445       * Encoded only for request inlining. Decoded right away by the controller
1446       * at static
1447       * {@link #setPreparedStatement(String, java.sql.PreparedStatement)}
1448       */

1449      String JavaDoc encodedString = AbstractBlobFilter.getDefaultBlobFilter()
1450          .encode(x);
1451      setNamedParameterWithTag(parameterName,
1452          PreparedStatementSerializationConstants.BYTES_TAG, encodedString);
1453    }
1454    catch (OutOfMemoryError JavaDoc oome)
1455    {
1456      System.gc();
1457      throw new SQLException JavaDoc("Out of memory while encoding bytes");
1458    }
1459  }
1460
1461  /**
1462   * Sets the designated parameter to the given <code>java.sql.Date</code>
1463   * value. The driver converts this to an SQL <code>DATE</code> value when it
1464   * sends it to the database.
1465   *
1466   * @param parameterName the name of the parameter
1467   * @param x the parameter value
1468   * @exception SQLException if a database access error occurs
1469   * @see #getDate(String)
1470   * @since 1.4
1471   */

1472  public void setDate(String JavaDoc parameterName, Date JavaDoc x) throws SQLException JavaDoc
1473  {
1474    if (x == null)
1475      setNamedParameterWithTag(parameterName,
1476          PreparedStatementSerializationConstants.DATE_TAG,
1477          PreparedStatementSerializationConstants.NULL_VALUE);
1478    else
1479      setNamedParameterWithTag(parameterName,
1480          PreparedStatementSerializationConstants.DATE_TAG, new java.sql.Date JavaDoc(x
1481              .getTime()).toString());
1482  }
1483
1484  /**
1485   * Sets the designated parameter to the given <code>java.sql.Time</code>
1486   * value. The driver converts this to an SQL <code>TIME</code> value when it
1487   * sends it to the database.
1488   *
1489   * @param parameterName the name of the parameter
1490   * @param x the parameter value
1491   * @exception SQLException if a database access error occurs
1492   * @see #getTime(String)
1493   * @since 1.4
1494   */

1495  public void setTime(String JavaDoc parameterName, Time JavaDoc x) throws SQLException JavaDoc
1496  {
1497    if (x == null)
1498      setNamedParameterWithTag(parameterName,
1499          PreparedStatementSerializationConstants.TIME_TAG,
1500          PreparedStatementSerializationConstants.NULL_VALUE);
1501    else
1502      setNamedParameterWithTag(parameterName,
1503          PreparedStatementSerializationConstants.TIME_TAG, x.toString());
1504  }
1505
1506  /**
1507   * Sets the designated parameter to the given <code>java.sql.Timestamp</code>
1508   * value. The driver converts this to an SQL <code>TIMESTAMP</code> value
1509   * when it sends it to the database.
1510   *
1511   * @param parameterName the name of the parameter
1512   * @param x the parameter value
1513   * @exception SQLException if a database access error occurs
1514   * @see #getTimestamp(String)
1515   * @since 1.4
1516   */

1517  public void setTimestamp(String JavaDoc parameterName, Timestamp JavaDoc x)
1518      throws SQLException JavaDoc
1519  {
1520    if (x == null)
1521      setNamedParameterWithTag(parameterName,
1522          PreparedStatementSerializationConstants.TIMESTAMP_TAG,
1523          PreparedStatementSerializationConstants.NULL_VALUE);
1524    else
1525    {
1526      if (x.getClass().equals(Timestamp JavaDoc.class))
1527        setNamedParameterWithTag(parameterName,
1528            PreparedStatementSerializationConstants.TIMESTAMP_TAG,
1529            new Timestamp JavaDoc(x.getTime()).toString());
1530    }
1531  }
1532
1533  /**
1534   * Sets the designated parameter to the given input stream, which will have
1535   * the specified number of bytes. When a very large ASCII value is input to a
1536   * <code>LONGVARCHAR</code> parameter, it may be more practical to send it
1537   * via a <code>java.io.InputStream</code>. Data will be read from the
1538   * stream as needed until end-of-file is reached. The JDBC driver will do any
1539   * necessary conversion from ASCII to the database char format.
1540   * <p>
1541   * <b>Note: </b> This stream object can either be a standard Java stream
1542   * object or your own subclass that implements the standard interface.
1543   *
1544   * @param parameterName the name of the parameter
1545   * @param x the Java input stream that contains the ASCII parameter value
1546   * @param length the number of bytes in the stream
1547   * @exception SQLException if a database access error occurs
1548   * @since 1.4
1549   */

1550  public void setAsciiStream(String JavaDoc parameterName, InputStream JavaDoc x, int length)
1551      throws SQLException JavaDoc
1552  {
1553    setBinaryStream(parameterName, x, length);
1554  }
1555
1556  /**
1557   * Sets the designated parameter to the given input stream, which will have
1558   * the specified number of bytes. When a very large binary value is input to a
1559   * <code>LONGVARBINARY</code> parameter, it may be more practical to send it
1560   * via a <code>java.io.InputStream</code> object. The data will be read from
1561   * the stream as needed until end-of-file is reached.
1562   * <p>
1563   * <b>Note: </b> This stream object can either be a standard Java stream
1564   * object or your own subclass that implements the standard interface.
1565   *
1566   * @param parameterName the name of the parameter
1567   * @param x the java input stream which contains the binary parameter value
1568   * @param length the number of bytes in the stream
1569   * @exception SQLException if a database access error occurs
1570   * @since 1.4
1571   */

1572  public void setBinaryStream(String JavaDoc parameterName, InputStream JavaDoc x, int length)
1573      throws SQLException JavaDoc
1574  {
1575    byte[] data = new byte[length];
1576    try
1577    {
1578      x.read(data, 0, length);
1579    }
1580    catch (Exception JavaDoc ioe)
1581    {
1582      throw new SQLException JavaDoc("Problem with streaming of data");
1583    }
1584    // TODO: optimize me and avoid the copy thanks to a new setBytesFromStream()
1585
// setBytes does the blob filter encoding.
1586
setBytes(parameterName, data);
1587  }
1588
1589  /**
1590   * Sets the value of the designated parameter with the given object. The
1591   * second argument must be an object type; for integral values, the
1592   * <code>java.lang</code> equivalent objects should be used.
1593   * <p>
1594   * The given Java object will be converted to the given
1595   * <code>targetSqlType</code> before being sent to the database.
1596   * <p>
1597   * If the object has a custom mapping (is of a class implementing the
1598   * interface <code>SQLData</code>), the JDBC driver should call the method
1599   * <code>SQLData.writeSQL</code> to write it to the SQL data stream. If, on
1600   * the other hand, the object is of a class implementing <code>Ref</code>,
1601   * <code>Blob</code>,<code>Clob</code>,<code>Struct</code>, or
1602   * <code>Array</code>, the driver should pass it to the database as a value
1603   * of the corresponding SQL type.
1604   * <p>
1605   * Note that this method may be used to pass datatabase-specific abstract data
1606   * types.
1607   *
1608   * @param parameterName the name of the parameter
1609   * @param x the object containing the input parameter value
1610   * @param targetSqlType the SQL type (as defined in
1611   * <code>java.sql.Types</code>) to be sent to the database. The
1612   * scale argument may further qualify this type.
1613   * @param scale for <code>java.sql.Types.DECIMAL</code> or
1614   * <code>java.sql.Types.NUMERIC</code> types, this is the number of
1615   * digits after the decimal point. For all other types, this value
1616   * will be ignored.
1617   * @exception SQLException if a database access error occurs
1618   * @see java.sql.Types
1619   * @see #getObject(String, Map)
1620   * @since 1.4
1621   */

1622  public void setObject(String JavaDoc parameterName, Object JavaDoc x, int targetSqlType,
1623      int scale) throws SQLException JavaDoc
1624  {
1625    if (x == null)
1626    {
1627      setNull(parameterName, targetSqlType);
1628      return;
1629    }
1630
1631    try
1632    {
1633      boolean failed = false;
1634      switch (targetSqlType)
1635      {
1636        /**
1637         * Reference is table "Conversions Performed by setObject()..." in JDBC
1638         * Reference Book (table 47.9.5 in 2nd edition, 50.5 in 3rd edition).
1639         * Also available online in Sun's "JDBC Technology Guide: Getting
1640         * Started", section "Mapping SQL and Java Types".
1641         */

1642        // Some drivers (at least postgresql > 8.1) don't accept setInt for tiny
1643
// and small ints. We can safely use setShort instead. See bug
1644
// SEQUOIA-543
1645
// setShort().
1646
case Types.TINYINT :
1647        case Types.SMALLINT :
1648          if (x instanceof Number JavaDoc)
1649            setShort(parameterName, ((Number JavaDoc) x).shortValue());
1650          else if (x instanceof Boolean JavaDoc)
1651            setShort(parameterName, ((Boolean JavaDoc) x).booleanValue()
1652                ? (short) 1
1653                : (short) 0);
1654          else if (x instanceof String JavaDoc)
1655            setInt(parameterName, Short.parseShort((String JavaDoc) x));
1656          else
1657            failed = true;
1658          break;
1659        // setInt()
1660
case Types.INTEGER :
1661          if (x instanceof Number JavaDoc)
1662            setInt(parameterName, ((Number JavaDoc) x).intValue());
1663          else if (x instanceof Boolean JavaDoc)
1664            setInt(parameterName, ((Boolean JavaDoc) x).booleanValue() ? 1 : 0);
1665          else if (x instanceof String JavaDoc)
1666            setInt(parameterName, Integer.parseInt((String JavaDoc) x));
1667          else
1668            failed = true;
1669          break;
1670        // setLong()
1671
case Types.BIGINT :
1672          if (x instanceof Number JavaDoc)
1673            setLong(parameterName, ((Number JavaDoc) x).longValue());
1674          else if (x instanceof String JavaDoc)
1675            setLong(parameterName, Long.parseLong((String JavaDoc) x));
1676          else if (x instanceof Boolean JavaDoc)
1677            setLong(parameterName, ((Boolean JavaDoc) x).booleanValue() ? 1 : 0);
1678          else
1679            failed = true;
1680          break;
1681        // setDouble()
1682
case Types.REAL :
1683        case Types.FLOAT :
1684        case Types.DOUBLE :
1685          if (x instanceof Number JavaDoc)
1686            setDouble(parameterName, ((Number JavaDoc) x).doubleValue());
1687          else if (x instanceof String JavaDoc)
1688            setDouble(parameterName, Double.parseDouble((String JavaDoc) x));
1689          else if (x instanceof Boolean JavaDoc)
1690            setDouble(parameterName, ((Boolean JavaDoc) x).booleanValue() ? 1 : 0);
1691          else
1692            failed = true;
1693          break;
1694        // setBigDecimal()
1695
case Types.DECIMAL :
1696        case Types.NUMERIC :
1697          BigDecimal JavaDoc bd;
1698          if (x instanceof Boolean JavaDoc)
1699            bd = new BigDecimal JavaDoc(((Boolean JavaDoc) x).booleanValue() ? 1d : 0d);
1700          else if (x instanceof Number JavaDoc)
1701            bd = new BigDecimal JavaDoc(((Number JavaDoc) x).toString());
1702          else if (x instanceof String JavaDoc)
1703            bd = new BigDecimal JavaDoc((String JavaDoc) x);
1704          else
1705          {
1706            failed = true;
1707            break;
1708          }
1709          bd = bd.setScale(scale, BigDecimal.ROUND_HALF_UP);
1710          setBigDecimal(parameterName, bd);
1711          break;
1712        // setBoolean()
1713
case Types.BIT :
1714        case Types.BOOLEAN :
1715          if (x instanceof Number JavaDoc)
1716            setBoolean(parameterName, 0 != ((Number JavaDoc) x).longValue());
1717          else if (x instanceof Boolean JavaDoc)
1718            setBoolean(parameterName, ((Boolean JavaDoc) x).booleanValue());
1719          else if (x instanceof String JavaDoc)
1720            setBoolean(parameterName, Boolean.valueOf((String JavaDoc) x)
1721                .booleanValue());
1722          else
1723            failed = true;
1724          break;
1725        // setString()
1726
case Types.CHAR :
1727        case Types.VARCHAR :
1728        case Types.LONGVARCHAR :
1729          setString(parameterName, x.toString());
1730          break;
1731        // setBytes(), setBlob(),...
1732
case Types.BINARY :
1733        case Types.VARBINARY :
1734        case Types.LONGVARBINARY :
1735          if (x instanceof byte[])
1736            setBytes(parameterName, (byte[]) x);
1737          else if (x instanceof Serializable JavaDoc)
1738            // Try it as an Object (serialized in bytes in setObject below)
1739
setObject(parameterName, x);
1740          else
1741            failed = true;
1742          break;
1743        // setDate()
1744
case Types.DATE :
1745          if (x instanceof String JavaDoc)
1746            setDate(parameterName, java.sql.Date.valueOf((String JavaDoc) x));
1747          else if (x instanceof java.sql.Date JavaDoc)
1748            setDate(parameterName, (java.sql.Date JavaDoc) x);
1749          else if (x instanceof Timestamp JavaDoc)
1750            setDate(parameterName, new java.sql.Date JavaDoc(((Timestamp JavaDoc) x).getTime()));
1751          else
1752            failed = true;
1753          break;
1754        // setTime()
1755
case Types.TIME :
1756          if (x instanceof String JavaDoc)
1757            setTime(parameterName, Time.valueOf((String JavaDoc) x));
1758          else if (x instanceof Time JavaDoc)
1759            setTime(parameterName, (Time JavaDoc) x);
1760          else if (x instanceof Timestamp JavaDoc)
1761            setTime(parameterName, new Time JavaDoc(((Timestamp JavaDoc) x).getTime()));
1762          else
1763            failed = true;
1764          break;
1765        // setTimeStamp()
1766
case Types.TIMESTAMP :
1767          if (x instanceof String JavaDoc)
1768            setTimestamp(parameterName, Timestamp.valueOf((String JavaDoc) x));
1769          else if (x instanceof Date JavaDoc)
1770            setTimestamp(parameterName, new Timestamp JavaDoc(((Date JavaDoc) x).getTime()));
1771          else if (x instanceof Timestamp JavaDoc)
1772            setTimestamp(parameterName, (Timestamp JavaDoc) x);
1773          else
1774            failed = true;
1775          break;
1776        // setBlob()
1777
case Types.BLOB :
1778          failed = true;
1779          break;
1780        // setURL()
1781
case Types.DATALINK :
1782          if (x instanceof java.net.URL JavaDoc)
1783            setURL(parameterName, (java.net.URL JavaDoc) x);
1784          else
1785            setURL(parameterName, new java.net.URL JavaDoc(x.toString()));
1786          break;
1787        case Types.JAVA_OBJECT :
1788        case Types.OTHER :
1789          // let's ignore the unknown target type given.
1790
setObject(parameterName, x);
1791          break;
1792        default :
1793          throw new SQLException JavaDoc("Unsupported type value");
1794      }
1795      if (true == failed)
1796        throw new IllegalArgumentException JavaDoc(
1797            "Attempt to perform an illegal conversion");
1798    }
1799    catch (Exception JavaDoc e)
1800    {
1801      SQLException JavaDoc outE = new SQLException JavaDoc("Exception while converting type "
1802          + x.getClass() + " to SQL type " + targetSqlType);
1803      outE.initCause(e);
1804      throw outE;
1805    }
1806  }
1807
1808  /**
1809   * Sets the value of the designated parameter with the given object. This
1810   * method is like the method <code>setObject</code> above, except that it
1811   * assumes a scale of zero.
1812   *
1813   * @param parameterName the name of the parameter
1814   * @param x the object containing the input parameter value
1815   * @param targetSqlType the SQL type (as defined in
1816   * <code>java.sql.Types</code>) to be sent to the database
1817   * @exception SQLException if a database access error occurs
1818   * @see #getObject(String, Map)
1819   * @since 1.4
1820   */

1821  public void setObject(String JavaDoc parameterName, Object JavaDoc x, int targetSqlType)
1822      throws SQLException JavaDoc
1823  {
1824    setObject(parameterName, x, targetSqlType, 0);
1825  }
1826
1827  /**
1828   * Sets the value of the designated parameter with the given object. The
1829   * second parameter must be of type <code>Object</code>; therefore, the
1830   * <code>java.lang</code> equivalent objects should be used for built-in
1831   * types.
1832   * <p>
1833   * The JDBC specification specifies a standard mapping from Java
1834   * <code>Object</code> types to SQL types. The given argument will be
1835   * converted to the corresponding SQL type before being sent to the database.
1836   * <p>
1837   * Note that this method may be used to pass datatabase-specific abstract data
1838   * types, by using a driver-specific Java type.
1839   * <p>
1840   * If the object is of a class implementing the interface <code>SQLData</code>,
1841   * the JDBC driver should call the method <code>SQLData.writeSQL</code> to
1842   * write it to the SQL data stream. If, on the other hand, the object is of a
1843   * class implementing <code>Ref</code>,<code>Blob</code>,
1844   * <code>Clob</code>,<code>Struct</code>, or <code>Array</code>, the
1845   * driver should pass it to the database as a value of the corresponding SQL
1846   * type.
1847   * <p>
1848   * This method throws an exception if there is an ambiguity, for example, if
1849   * the object is of a class implementing more than one of the interfaces named
1850   * above.
1851   *
1852   * @param parameterName the name of the parameter
1853   * @param x the object containing the input parameter value
1854   * @exception SQLException if a database access error occurs or if the given
1855   * <code>Object</code> parameter is ambiguous
1856   * @see #getObject(String, Map)
1857   * @since 1.4
1858   */

1859  public void setObject(String JavaDoc parameterName, Object JavaDoc x) throws SQLException JavaDoc
1860  {
1861    if (x == null)
1862    {
1863      setNamedParameterWithTag(parameterName,
1864          PreparedStatementSerializationConstants.OBJECT_TAG,
1865          PreparedStatementSerializationConstants.NULL_VALUE);
1866    }
1867    else
1868    { // This is an optimization, faster than going through
1869
// the generic setObject() method and calling instanceof again.
1870
// This has to be in the end equivalent to
1871
// setObject(index, object, DEFAULT_targetSqlType, 0)
1872
// where DEFAULT_targetSqlType is defined in table:
1873
// "Java Object Type Mapped to JDBC Types".
1874
// It's currently not exactly the same, since generic setObject()
1875
// is not strict enough in its conversions. For instance
1876
// setObject(target=Float) actually calls "setDouble()" -- MH.
1877

1878      if (x instanceof String JavaDoc)
1879        setString(parameterName, (String JavaDoc) x);
1880      else if (x instanceof BigDecimal JavaDoc)
1881        setBigDecimal(parameterName, (BigDecimal JavaDoc) x);
1882      else if (x instanceof Boolean JavaDoc)
1883        setBoolean(parameterName, ((Boolean JavaDoc) x).booleanValue());
1884      else if (x instanceof Short JavaDoc)
1885        setShort(parameterName, ((Short JavaDoc) x).shortValue());
1886      else if (x instanceof Integer JavaDoc)
1887        setInt(parameterName, ((Integer JavaDoc) x).intValue());
1888      else if (x instanceof Long JavaDoc)
1889        setLong(parameterName, ((Long JavaDoc) x).longValue());
1890      else if (x instanceof Float JavaDoc)
1891        setFloat(parameterName, ((Float JavaDoc) x).floatValue());
1892      else if (x instanceof Double JavaDoc)
1893        setDouble(parameterName, ((Double JavaDoc) x).doubleValue());
1894      else if (x instanceof byte[])
1895        setBytes(parameterName, (byte[]) x);
1896      else if (x instanceof java.sql.Date JavaDoc)
1897        setDate(parameterName, (java.sql.Date JavaDoc) x);
1898      else if (x instanceof Time JavaDoc)
1899        setTime(parameterName, (Time JavaDoc) x);
1900      else if (x instanceof Timestamp JavaDoc)
1901        setTimestamp(parameterName, (Timestamp JavaDoc) x);
1902      else if (x instanceof java.net.URL JavaDoc)
1903        setURL(parameterName, (java.net.URL JavaDoc) x);
1904      else if (x instanceof Serializable JavaDoc)
1905      {
1906        ByteArrayOutputStream JavaDoc byteOutputStream = new ByteArrayOutputStream JavaDoc();
1907        try
1908        {
1909          // Serialize object to byte array
1910
ObjectOutputStream JavaDoc objectOutputStream = new ObjectOutputStream JavaDoc(
1911              byteOutputStream);
1912          objectOutputStream.writeObject(x);
1913          objectOutputStream.close();
1914          synchronized (this.sbuf)
1915          {
1916            this.sbuf.setLength(0);
1917            /**
1918             * Encoded only for request inlining. Decoded right away by the
1919             * controller
1920             */

1921            this.sbuf.append(AbstractBlobFilter.getDefaultBlobFilter().encode(
1922                byteOutputStream.toByteArray()));
1923            setNamedParameterWithTag(parameterName,
1924                PreparedStatementSerializationConstants.OBJECT_TAG, this.sbuf
1925                    .toString());
1926          }
1927        }
1928        catch (IOException JavaDoc e)
1929        {
1930          throw new SQLException JavaDoc("Failed to serialize object: " + e);
1931        }
1932      }
1933      else
1934        throw new SQLException JavaDoc("Objects of type " + x.getClass()
1935            + " are not supported.");
1936    }
1937  }
1938
1939  /**
1940   * Sets the designated parameter to the given <code>Reader</code> object,
1941   * which is the given number of characters long. When a very large UNICODE
1942   * value is input to a <code>LONGVARCHAR</code> parameter, it may be more
1943   * practical to send it via a <code>java.io.Reader</code> object. The data
1944   * will be read from the stream as needed until end-of-file is reached. The
1945   * JDBC driver will do any necessary conversion from UNICODE to the database
1946   * char format.
1947   * <p>
1948   * <b>Note: </b> This stream object can either be a standard Java stream
1949   * object or your own subclass that implements the standard interface.
1950   *
1951   * @param parameterName the name of the parameter
1952   * @param reader the <code>java.io.Reader</code> object that contains the
1953   * UNICODE data used as the designated parameter
1954   * @param length the number of characters in the stream
1955   * @exception SQLException if a database access error occurs
1956   * @since 1.4
1957   */

1958  public void setCharacterStream(String JavaDoc parameterName, Reader JavaDoc reader, int length)
1959      throws SQLException JavaDoc
1960  {
1961    char[] data = new char[length];
1962    try
1963    {
1964      reader.read(data, 0, length);
1965    }
1966    catch (Exception JavaDoc ioe)
1967    {
1968      throw new SQLException JavaDoc("Problem with streaming of data");
1969    }
1970    setString(parameterName, new String JavaDoc(data));
1971  }
1972
1973  /**
1974   * Sets the designated parameter to the given <code>java.sql.Date</code>
1975   * value, using the given <code>Calendar</code> object. The driver uses the
1976   * <code>Calendar</code> object to construct an SQL <code>DATE</code>
1977   * value, which the driver then sends to the database. With a a
1978   * <code>Calendar</code> object, the driver can calculate the date taking
1979   * into account a custom timezone. If no <code>Calendar</code> object is
1980   * specified, the driver uses the default timezone, which is that of the
1981   * virtual machine running the application.
1982   *
1983   * @param parameterName the name of the parameter
1984   * @param d the parameter value
1985   * @param cal the <code>Calendar</code> object the driver will use to
1986   * construct the date
1987   * @exception SQLException if a database access error occurs
1988   * @see #getDate(String, Calendar)
1989   * @since 1.4
1990   */

1991  public void setDate(String JavaDoc parameterName, Date JavaDoc d, Calendar JavaDoc cal)
1992      throws SQLException JavaDoc
1993  {
1994    if (d == null)
1995      setNamedParameterWithTag(parameterName,
1996          PreparedStatementSerializationConstants.DATE_TAG,
1997          PreparedStatementSerializationConstants.NULL_VALUE);
1998    else
1999    {
2000      if (cal == null)
2001        setDate(parameterName, d);
2002      else
2003      {
2004        cal.setTime(d);
2005        setDate(parameterName, new java.sql.Date JavaDoc(cal.getTime().getTime()));
2006      }
2007    }
2008  }
2009
2010  /**
2011   * Sets the designated parameter to the given <code>java.sql.Time</code>
2012   * value, using the given <code>Calendar</code> object. The driver uses the
2013   * <code>Calendar</code> object to construct an SQL <code>TIME</code>
2014   * value, which the driver then sends to the database. With a a
2015   * <code>Calendar</code> object, the driver can calculate the time taking
2016   * into account a custom timezone. If no <code>Calendar</code> object is
2017   * specified, the driver uses the default timezone, which is that of the
2018   * virtual machine running the application.
2019   *
2020   * @param parameterName the name of the parameter
2021   * @param t the parameter value
2022   * @param cal the <code>Calendar</code> object the driver will use to
2023   * construct the time
2024   * @exception SQLException if a database access error occurs
2025   * @see #getTime(String, Calendar)
2026   * @since 1.4
2027   */

2028  public void setTime(String JavaDoc parameterName, Time JavaDoc t, Calendar JavaDoc cal)
2029      throws SQLException JavaDoc
2030  {
2031    if (t == null)
2032      setNamedParameterWithTag(parameterName,
2033          PreparedStatementSerializationConstants.TIME_TAG,
2034          PreparedStatementSerializationConstants.NULL_VALUE);
2035    else
2036    {
2037      if (cal == null)
2038        setTime(parameterName, t);
2039      else
2040      {
2041        cal.setTime(t);
2042        setTime(parameterName, new java.sql.Time JavaDoc(cal.getTime().getTime()));
2043      }
2044    }
2045  }
2046
2047  /**
2048   * Sets the designated parameter to the given <code>java.sql.Timestamp</code>
2049   * value, using the given <code>Calendar</code> object. The driver uses the
2050   * <code>Calendar</code> object to construct an SQL <code>TIMESTAMP</code>
2051   * value, which the driver then sends to the database. With a a
2052   * <code>Calendar</code> object, the driver can calculate the timestamp
2053   * taking into account a custom timezone. If no <code>Calendar</code> object
2054   * is specified, the driver uses the default timezone, which is that of the
2055   * virtual machine running the application.
2056   *
2057   * @param parameterName the name of the parameter
2058   * @param t the parameter value
2059   * @param cal the <code>Calendar</code> object the driver will use to
2060   * construct the timestamp
2061   * @exception SQLException if a database access error occurs
2062   * @see #getTimestamp(String, Calendar)
2063   * @since 1.4
2064   */

2065  public void setTimestamp(String JavaDoc parameterName, Timestamp JavaDoc t, Calendar JavaDoc cal)
2066      throws SQLException JavaDoc
2067  {
2068    if (t == null)
2069      setNamedParameterWithTag(parameterName,
2070          PreparedStatementSerializationConstants.TIMESTAMP_TAG,
2071          PreparedStatementSerializationConstants.NULL_VALUE);
2072    else
2073    {
2074      if (cal == null)
2075        setTimestamp(parameterName, t);
2076      else
2077      {
2078        cal.setTime(t);
2079        setTimestamp(parameterName, new java.sql.Timestamp JavaDoc(cal.getTime()
2080            .getTime()));
2081      }
2082    }
2083  }
2084
2085  /**
2086   * Sets the designated parameter to SQL <code>NULL</code>. This version of
2087   * the method <code>setNull</code> should be used for user-defined types and
2088   * REF type parameters. Examples of user-defined types include: STRUCT,
2089   * DISTINCT, JAVA_OBJECT, and named array types.
2090   * <p>
2091   * <b>Note: </b> to be portable, applications must give the SQL type code and
2092   * the fully-qualified SQL type name when specifying a NULL user-defined or
2093   * REF parameter. In the case of a user-defined type the name is the type name
2094   * of the parameter itself. For a REF parameter, the name is the type name of
2095   * the referenced type. If a JDBC driver does not need the type code or type
2096   * name information, it may ignore it.
2097   * <p>
2098   * Although it is intended for user-defined and Ref parameters, this method
2099   * may be used to set a null parameter of any JDBC type. If the parameter does
2100   * not have a user-defined or REF type, the given typeName is ignored.
2101   *
2102   * @param parameterName the name of the parameter
2103   * @param sqlType a value from <code>java.sql.Types</code>
2104   * @param typeName the fully-qualified name of an SQL user-defined type;
2105   * ignored if the parameter is not a user-defined type or SQL
2106   * <code>REF</code> value
2107   * @exception SQLException if a database access error occurs
2108   * @since 1.4
2109   */

2110  public void setNull(String JavaDoc parameterName, int sqlType, String JavaDoc typeName)
2111      throws SQLException JavaDoc
2112  {
2113    setNull(parameterName, sqlType);
2114  }
2115
2116  /**
2117   * Retrieves the value of a JDBC <code>CHAR</code>,<code>VARCHAR</code>,
2118   * or <code>LONGVARCHAR</code> parameter as a <code>String</code> in the
2119   * Java programming language.
2120   * <p>
2121   * For the fixed-length type JDBC <code>CHAR</code>, the
2122   * <code>String</code> object returned has exactly the same value the JDBC
2123   * <code>CHAR</code> value had in the database, including any padding added
2124   * by the database.
2125   *
2126   * @param parameterName the name of the parameter
2127   * @return the parameter value. If the value is SQL <code>NULL</code>, the
2128   * result is <code>null</code>.
2129   * @exception SQLException if a database access error occurs
2130   * @see #setString
2131   * @since 1.4
2132   */

2133  public String JavaDoc getString(String JavaDoc parameterName) throws SQLException JavaDoc
2134  {
2135    if (!outAndNamedParameterTypes.containsKey(parameterName))
2136      throw new SQLException JavaDoc("Invalid named parameter " + parameterName);
2137
2138    try
2139    {
2140      return (String JavaDoc) namedParameterValues.get(parameterName);
2141    }
2142    catch (Exception JavaDoc e)
2143    {
2144      throw new SQLException JavaDoc("Unable to convert named parameter "
2145          + parameterName + " to the requested type");
2146    }
2147  }
2148
2149  /**
2150   * Retrieves the value of a JDBC <code>BIT</code> parameter as a
2151   * <code>boolean</code> in the Java programming language.
2152   *
2153   * @param parameterName the name of the parameter
2154   * @return the parameter value. If the value is SQL <code>NULL</code>, the
2155   * result is <code>false</code>.
2156   * @exception SQLException if a database access error occurs
2157   * @see #setBoolean
2158   * @since 1.4
2159   */

2160  public boolean getBoolean(String JavaDoc parameterName) throws SQLException JavaDoc
2161  {
2162    if (!outAndNamedParameterTypes.containsKey(parameterName))
2163      throw new SQLException JavaDoc("Invalid named parameter " + parameterName);
2164
2165    try
2166    {
2167      Boolean JavaDoc b = (Boolean JavaDoc) namedParameterValues.get(parameterName);
2168      if (b == null)
2169        return false;
2170      else
2171        return b.booleanValue();
2172    }
2173    catch (Exception JavaDoc e)
2174    {
2175      throw new SQLException JavaDoc("Unable to convert named parameter "
2176          + parameterName + " to the requested type");
2177    }
2178  }
2179
2180  /**
2181   * Retrieves the value of a JDBC <code>TINYINT</code> parameter as a
2182   * <code>byte</code> in the Java programming language.
2183   *
2184   * @param parameterName the name of the parameter
2185   * @return the parameter value. If the value is SQL <code>NULL</code>, the
2186   * result is <code>0</code>.
2187   * @exception SQLException if a database access error occurs
2188   * @see #setByte
2189   * @since 1.4
2190   */

2191  public byte getByte(String JavaDoc parameterName) throws SQLException JavaDoc
2192  {
2193    if (!outAndNamedParameterTypes.containsKey(parameterName))
2194      throw new SQLException JavaDoc("Invalid named parameter " + parameterName);
2195
2196    try
2197    {
2198      Byte JavaDoc b = (Byte JavaDoc) namedParameterValues.get(parameterName);
2199      if (b == null)
2200        return 0;
2201      else
2202        return b.byteValue();
2203    }
2204    catch (Exception JavaDoc e)
2205    {
2206      throw new SQLException JavaDoc("Unable to convert named parameter "
2207          + parameterName + " to the requested type");
2208    }
2209  }
2210
2211  /**
2212   * Retrieves the value of a JDBC <code>SMALLINT</code> parameter as a
2213   * <code>short</code> in the Java programming language.
2214   *
2215   * @param parameterName the name of the parameter
2216   * @return the parameter value. If the value is SQL <code>NULL</code>, the
2217   * result is <code>0</code>.
2218   * @exception SQLException if a database access error occurs
2219   * @see #setShort
2220   * @since 1.4
2221   */

2222  public short getShort(String JavaDoc parameterName) throws SQLException JavaDoc
2223  {
2224    if (!outAndNamedParameterTypes.containsKey(parameterName))
2225      throw new SQLException JavaDoc("Invalid named parameter " + parameterName);
2226
2227    try
2228    {
2229      Short JavaDoc s = (Short JavaDoc) namedParameterValues.get(parameterName);
2230      if (s == null)
2231        return 0;
2232      else
2233        return s.shortValue();
2234    }
2235    catch (Exception JavaDoc e)
2236    {
2237      throw new SQLException JavaDoc("Unable to convert named parameter "
2238          + parameterName + " to the requested type");
2239    }
2240  }
2241
2242  /**
2243   * Retrieves the value of a JDBC <code>INTEGER</code> parameter as an
2244   * <code>int</code> in the Java programming language.
2245   *
2246   * @param parameterName the name of the parameter
2247   * @return the parameter value. If the value is SQL <code>NULL</code>, the
2248   * result is <code>0</code>.
2249   * @exception SQLException if a database access error occurs
2250   * @see #setInt
2251   * @since 1.4
2252   */

2253  public int getInt(String JavaDoc parameterName) throws SQLException JavaDoc
2254  {
2255    if (!outAndNamedParameterTypes.containsKey(parameterName))
2256      throw new SQLException JavaDoc("Invalid named parameter " + parameterName);
2257
2258    try
2259    {
2260      Integer JavaDoc i = (Integer JavaDoc) namedParameterValues.get(parameterName);
2261      if (i == null)
2262        return 0;
2263      else
2264        return i.intValue();
2265    }
2266    catch (Exception JavaDoc e)
2267    {
2268      throw new SQLException JavaDoc("Unable to convert named parameter "
2269          + parameterName + " to the requested type");
2270    }
2271  }
2272
2273  /**
2274   * Retrieves the value of a JDBC <code>BIGINT</code> parameter as a
2275   * <code>long</code> in the Java programming language.
2276   *
2277   * @param parameterName the name of the parameter
2278   * @return the parameter value. If the value is SQL <code>NULL</code>, the
2279   * result is <code>0</code>.
2280   * @exception SQLException if a database access error occurs
2281   * @see #setLong
2282   * @since 1.4
2283   */

2284  public long getLong(String JavaDoc parameterName) throws SQLException JavaDoc
2285  {
2286    if (!outAndNamedParameterTypes.containsKey(parameterName))
2287      throw new SQLException JavaDoc("Invalid named parameter " + parameterName);
2288
2289    try
2290    {
2291      Long JavaDoc l = (Long JavaDoc) namedParameterValues.get(parameterName);
2292      if (l == null)
2293        return 0;
2294      else
2295        return l.longValue();
2296    }
2297    catch (Exception JavaDoc e)
2298    {
2299      throw new SQLException JavaDoc("Unable to convert named parameter "
2300          + parameterName + " to the requested type");
2301    }
2302  }
2303
2304  /**
2305   * Retrieves the value of a JDBC <code>FLOAT</code> parameter as a
2306   * <code>float</code> in the Java programming language.
2307   *
2308   * @param parameterName the name of the parameter
2309   * @return the parameter value. If the value is SQL <code>NULL</code>, the
2310   * result is <code>0</code>.
2311   * @exception SQLException if a database access error occurs
2312   * @see #setFloat
2313   * @since 1.4
2314   */

2315  public float getFloat(String JavaDoc parameterName) throws SQLException JavaDoc
2316  {
2317    if (!outAndNamedParameterTypes.containsKey(parameterName))
2318      throw new SQLException JavaDoc("Invalid named parameter " + parameterName);
2319
2320    try
2321    {
2322      Float JavaDoc f = (Float JavaDoc) namedParameterValues.get(parameterName);
2323      if (f == null)
2324        return 0;
2325      else
2326        return f.floatValue();
2327    }
2328    catch (Exception JavaDoc e)
2329    {
2330      throw new SQLException JavaDoc("Unable to convert named parameter "
2331          + parameterName + " to the requested type");
2332    }
2333  }
2334
2335  /**
2336   * Retrieves the value of a JDBC <code>DOUBLE</code> parameter as a
2337   * <code>double</code> in the Java programming language.
2338   *
2339   * @param parameterName the name of the parameter
2340   * @return the parameter value. If the value is SQL <code>NULL</code>, the
2341   * result is <code>0</code>.
2342   * @exception SQLException if a database access error occurs
2343   * @see #setDouble
2344   * @since 1.4
2345   */

2346  public double getDouble(String JavaDoc parameterName) throws SQLException JavaDoc
2347  {
2348    if (!outAndNamedParameterTypes.containsKey(parameterName))
2349      throw new SQLException JavaDoc("Invalid named parameter " + parameterName);
2350
2351    try
2352    {
2353      Double JavaDoc d = (Double JavaDoc) namedParameterValues.get(parameterName);
2354      if (d == null)
2355        return 0;
2356      else
2357        return d.doubleValue();
2358    }
2359    catch (Exception JavaDoc e)
2360    {
2361      throw new SQLException JavaDoc("Unable to convert named parameter "
2362          + parameterName + " to the requested type");
2363    }
2364  }
2365
2366  /**
2367   * Retrieves the value of a JDBC <code>BINARY</code> or
2368   * <code>VARBINARY</code> parameter as an array of <code>byte</code>
2369   * values in the Java programming language.
2370   *
2371   * @param parameterName the name of the parameter
2372   * @return the parameter value. If the value is SQL <code>NULL</code>, the
2373   * result is <code>null</code>.
2374   * @exception SQLException if a database access error occurs
2375   * @see #setBytes
2376   * @since 1.4
2377   */

2378  public byte[] getBytes(String JavaDoc parameterName) throws SQLException JavaDoc
2379  {
2380    if (!outAndNamedParameterTypes.containsKey(parameterName))
2381      throw new SQLException JavaDoc("Invalid named parameter " + parameterName);
2382
2383    try
2384    {
2385      return (byte[]) namedParameterValues.get(parameterName);
2386    }
2387    catch (Exception JavaDoc e)
2388    {
2389      throw new SQLException JavaDoc("Unable to convert named parameter "
2390          + parameterName + " to the requested type");
2391    }
2392  }
2393
2394  /**
2395   * Retrieves the value of a JDBC <code>DATE</code> parameter as a
2396   * <code>java.sql.Date</code> object.
2397   *
2398   * @param parameterName the name of the parameter
2399   * @return the parameter value. If the value is SQL <code>NULL</code>, the
2400   * result is <code>null</code>.
2401   * @exception SQLException if a database access error occurs
2402   * @see #setDate(String, Date)
2403   * @since 1.4
2404   */

2405  public Date JavaDoc getDate(String JavaDoc parameterName) throws SQLException JavaDoc
2406  {
2407    if (!outAndNamedParameterTypes.containsKey(parameterName))
2408      throw new SQLException JavaDoc("Invalid named parameter " + parameterName);
2409
2410    try
2411    {
2412      return (Date JavaDoc) namedParameterValues.get(parameterName);
2413    }
2414    catch (Exception JavaDoc e)
2415    {
2416      throw new SQLException JavaDoc("Unable to convert named parameter "
2417          + parameterName + " to the requested type");
2418    }
2419  }
2420
2421  /**
2422   * Retrieves the value of a JDBC <code>TIME</code> parameter as a
2423   * <code>java.sql.Time</code> object.
2424   *
2425   * @param parameterName the name of the parameter
2426   * @return the parameter value. If the value is SQL <code>NULL</code>, the
2427   * result is <code>null</code>.
2428   * @exception SQLException if a database access error occurs
2429   * @see #setTime(String, Time)
2430   * @since 1.4
2431   */

2432  public Time JavaDoc getTime(String JavaDoc parameterName) throws SQLException JavaDoc
2433  {
2434    if (!outAndNamedParameterTypes.containsKey(parameterName))
2435      throw new SQLException JavaDoc("Invalid named parameter " + parameterName);
2436
2437    try
2438    {
2439      return (Time JavaDoc) namedParameterValues.get(parameterName);
2440    }
2441    catch (Exception JavaDoc e)
2442    {
2443      throw new SQLException JavaDoc("Unable to convert named parameter "
2444          + parameterName + " to the requested type");
2445    }
2446  }
2447
2448  /**
2449   * Retrieves the value of a JDBC <code>TIMESTAMP</code> parameter as a
2450   * <code>java.sql.Timestamp</code> object.
2451   *
2452   * @param parameterName the name of the parameter
2453   * @return the parameter value. If the value is SQL <code>NULL</code>, the
2454   * result is <code>null</code>.
2455   * @exception SQLException if a database access error occurs
2456   * @see #setTimestamp(String, Timestamp)
2457   * @since 1.4
2458   */

2459  public Timestamp JavaDoc getTimestamp(String JavaDoc parameterName) throws SQLException JavaDoc
2460  {
2461    if (!outAndNamedParameterTypes.containsKey(parameterName))
2462      throw new SQLException JavaDoc("Invalid named parameter " + parameterName);
2463
2464    try
2465    {
2466      return (Timestamp JavaDoc) namedParameterValues.get(parameterName);
2467    }
2468    catch (Exception JavaDoc e)
2469    {
2470      throw new SQLException JavaDoc("Unable to convert named parameter "
2471          + parameterName + " to the requested type");
2472    }
2473  }
2474
2475  /**
2476   * Retrieves the value of a parameter as an <code>Object</code> in the Java
2477   * programming language. If the value is an SQL <code>NULL</code>, the
2478   * driver returns a Java <code>null</code>.
2479   * <p>
2480   * This method returns a Java object whose type corresponds to the JDBC type
2481   * that was registered for this parameter using the method
2482   * <code>registerOutParameter</code>. By registering the target JDBC type
2483   * as <code>java.sql.Types.OTHER</code>, this method can be used to read
2484   * database-specific abstract data types.
2485   *
2486   * @param parameterName the name of the parameter
2487   * @return A <code>java.lang.Object</code> holding the OUT parameter value.
2488   * @exception SQLException if a database access error occurs
2489   * @see java.sql.Types
2490   * @see #setObject(String, Object)
2491   * @since 1.4
2492   */

2493  public Object JavaDoc getObject(String JavaDoc parameterName) throws SQLException JavaDoc
2494  {
2495    if (!outAndNamedParameterTypes.containsKey(parameterName))
2496      throw new SQLException JavaDoc("Invalid named parameter " + parameterName);
2497
2498    try
2499    {
2500      return namedParameterValues.get(parameterName);
2501    }
2502    catch (Exception JavaDoc e)
2503    {
2504      throw new SQLException JavaDoc("Unable to convert named parameter "
2505          + parameterName + " to the requested type");
2506    }
2507  }
2508
2509  /**
2510   * Retrieves the value of a JDBC <code>NUMERIC</code> parameter as a
2511   * <code>java.math.BigDecimal</code> object with as many digits to the right
2512   * of the decimal point as the value contains.
2513   *
2514   * @param parameterName the name of the parameter
2515   * @return the parameter value in full precision. If the value is SQL
2516   * <code>NULL</code>, the result is <code>null</code>.
2517   * @exception SQLException if a database access error occurs
2518   * @see #setBigDecimal
2519   * @since 1.4
2520   */

2521  public BigDecimal JavaDoc getBigDecimal(String JavaDoc parameterName) throws SQLException JavaDoc
2522  {
2523    if (!outAndNamedParameterTypes.containsKey(parameterName))
2524      throw new SQLException JavaDoc("Invalid named parameter " + parameterName);
2525
2526    try
2527    {
2528      return (BigDecimal JavaDoc) namedParameterValues.get(parameterName);
2529    }
2530    catch (Exception JavaDoc e)
2531    {
2532      throw new SQLException JavaDoc("Unable to convert named parameter "
2533          + parameterName + " to the requested type");
2534    }
2535  }
2536
2537  /**
2538   * Returns an object representing the value of OUT parameter <code>i</code>
2539   * and uses <code>map</code> for the custom mapping of the parameter value.
2540   * <p>
2541   * This method returns a Java object whose type corresponds to the JDBC type
2542   * that was registered for this parameter using the method
2543   * <code>registerOutParameter</code>. By registering the target JDBC type
2544   * as <code>java.sql.Types.OTHER</code>, this method can be used to read
2545   * database-specific abstract data types.
2546   *
2547   * @param parameterName the name of the parameter
2548   * @param map the mapping from SQL type names to Java classes
2549   * @return a <code>java.lang.Object</code> holding the OUT parameter value
2550   * @exception SQLException if a database access error occurs
2551   * @see #setObject(String, Object)
2552   * @since 1.4
2553   */

2554  public Object JavaDoc getObject(String JavaDoc parameterName, Map JavaDoc map) throws SQLException JavaDoc
2555  {
2556    throw new NotImplementedException("getObject");
2557  }
2558
2559  /**
2560   * Retrieves the value of a JDBC <code>REF(&lt;structured-type&gt;)</code>
2561   * parameter as a <code>Ref</code> object in the Java programming language.
2562   *
2563   * @param parameterName the name of the parameter
2564   * @return the parameter value as a <code>Ref</code> object in the Java
2565   * programming language. If the value was SQL <code>NULL</code>,
2566   * the value <code>null</code> is returned.
2567   * @exception SQLException if a database access error occurs
2568   * @since 1.4
2569   */

2570  public Ref JavaDoc getRef(String JavaDoc parameterName) throws SQLException JavaDoc
2571  {
2572    if (!outAndNamedParameterTypes.containsKey(parameterName))
2573      throw new SQLException JavaDoc("Invalid named parameter " + parameterName);
2574
2575    try
2576    {
2577      return (Ref JavaDoc) namedParameterValues.get(parameterName);
2578    }
2579    catch (Exception JavaDoc e)
2580    {
2581      throw new SQLException JavaDoc("Unable to convert named parameter "
2582          + parameterName + " to the requested type");
2583    }
2584  }
2585
2586  /**
2587   * Retrieves the value of a JDBC <code>BLOB</code> parameter as a
2588   * {@link Blob}object in the Java programming language.
2589   *
2590   * @param parameterName the name of the parameter
2591   * @return the parameter value as a <code>Blob</code> object in the Java
2592   * programming language. If the value was SQL <code>NULL</code>,
2593   * the value <code>null</code> is returned.
2594   * @exception SQLException if a database access error occurs
2595   * @since 1.4
2596   */

2597  public Blob JavaDoc getBlob(String JavaDoc parameterName) throws SQLException JavaDoc
2598  {
2599    if (!outAndNamedParameterTypes.containsKey(parameterName))
2600      throw new SQLException JavaDoc("Invalid named parameter " + parameterName);
2601
2602    try
2603    {
2604      return (Blob JavaDoc) namedParameterValues.get(parameterName);
2605    }
2606    catch (Exception JavaDoc e)
2607    {
2608      throw new SQLException JavaDoc("Unable to convert named parameter "
2609          + parameterName + " to the requested type");
2610    }
2611  }
2612
2613  /**
2614   * Retrieves the value of a JDBC <code>CLOB</code> parameter as a
2615   * <code>Clob</code> object in the Java programming language.
2616   *
2617   * @param parameterName the name of the parameter
2618   * @return the parameter value as a <code>Clob</code> object in the Java
2619   * programming language. If the value was SQL <code>NULL</code>,
2620   * the value <code>null</code> is returned.
2621   * @exception SQLException if a database access error occurs
2622   * @since 1.4
2623   */

2624  public Clob JavaDoc getClob(String JavaDoc parameterName) throws SQLException JavaDoc
2625  {
2626    if (!outAndNamedParameterTypes.containsKey(parameterName))
2627      throw new SQLException JavaDoc("Invalid named parameter " + parameterName);
2628
2629    try
2630    {
2631      return (Clob JavaDoc) namedParameterValues.get(parameterName);
2632    }
2633    catch (Exception JavaDoc e)
2634    {
2635      throw new SQLException JavaDoc("Unable to convert named parameter "
2636          + parameterName + " to the requested type");
2637    }
2638  }
2639
2640  /**
2641   * Retrieves the value of a JDBC <code>ARRAY</code> parameter as an
2642   * {@link Array}object in the Java programming language.
2643   *
2644   * @param parameterName the name of the parameter
2645   * @return the parameter value as an <code>Array</code> object in Java
2646   * programming language. If the value was SQL <code>NULL</code>,
2647   * the value <code>null</code> is returned.
2648   * @exception SQLException if a database access error occurs
2649   * @since 1.4
2650   */

2651  public Array JavaDoc getArray(String JavaDoc parameterName) throws SQLException JavaDoc
2652  {
2653    if (!outAndNamedParameterTypes.containsKey(parameterName))
2654      throw new SQLException JavaDoc("Invalid named parameter " + parameterName);
2655
2656    try
2657    {
2658      return (Array JavaDoc) namedParameterValues.get(parameterName);
2659    }
2660    catch (Exception JavaDoc e)
2661    {
2662      throw new SQLException JavaDoc("Unable to convert named parameter "
2663          + parameterName + " to the requested type");
2664    }
2665  }
2666
2667  /**
2668   * Retrieves the value of a JDBC <code>DATE</code> parameter as a
2669   * <code>java.sql.Date</code> object, using the given <code>Calendar</code>
2670   * object to construct the date. With a <code>Calendar</code> object, the
2671   * driver can calculate the date taking into account a custom timezone and
2672   * locale. If no <code>Calendar</code> object is specified, the driver uses
2673   * the default timezone and locale.
2674   *
2675   * @param parameterName the name of the parameter
2676   * @param cal the <code>Calendar</code> object the driver will use to
2677   * construct the date
2678   * @return the parameter value. If the value is SQL <code>NULL</code>, the
2679   * result is <code>null</code>.
2680   * @exception SQLException if a database access error occurs
2681   * @see #setDate(String, Date, Calendar)
2682   * @since 1.4
2683   */

2684  public Date JavaDoc getDate(String JavaDoc parameterName, Calendar JavaDoc cal) throws SQLException JavaDoc
2685  {
2686    return getDate(executeUpdate());
2687  }
2688
2689  /**
2690   * Retrieves the value of a JDBC <code>TIME</code> parameter as a
2691   * <code>java.sql.Time</code> object, using the given <code>Calendar</code>
2692   * object to construct the time. With a <code>Calendar</code> object, the
2693   * driver can calculate the time taking into account a custom timezone and
2694   * locale. If no <code>Calendar</code> object is specified, the driver uses
2695   * the default timezone and locale.
2696   *
2697   * @param parameterName the name of the parameter
2698   * @param cal the <code>Calendar</code> object the driver will use to
2699   * construct the time
2700   * @return the parameter value; if the value is SQL <code>NULL</code>, the
2701   * result is <code>null</code>.
2702   * @exception SQLException if a database access error occurs
2703   * @see #setTime(String, Time, Calendar)
2704   * @since 1.4
2705   */

2706  public Time JavaDoc getTime(String JavaDoc parameterName, Calendar JavaDoc cal) throws SQLException JavaDoc
2707  {
2708    return getTime(executeUpdate());
2709  }
2710
2711  /**
2712   * Retrieves the value of a JDBC <code>TIMESTAMP</code> parameter as a
2713   * <code>java.sql.Timestamp</code> object, using the given
2714   * <code>Calendar</code> object to construct the <code>Timestamp</code>
2715   * object. With a <code>Calendar</code> object, the driver can calculate the
2716   * timestamp taking into account a custom timezone and locale. If no
2717   * <code>Calendar</code> object is specified, the driver uses the default
2718   * timezone and locale.
2719   *
2720   * @param parameterName the name of the parameter
2721   * @param cal the <code>Calendar</code> object the driver will use to
2722   * construct the timestamp
2723   * @return the parameter value. If the value is SQL <code>NULL</code>, the
2724   * result is <code>null</code>.
2725   * @exception SQLException if a database access error occurs
2726   * @see #setTimestamp(String, Timestamp, Calendar)
2727   * @since 1.4
2728   */

2729  public Timestamp JavaDoc getTimestamp(String JavaDoc parameterName, Calendar JavaDoc cal)
2730      throws SQLException JavaDoc
2731  {
2732    return getTimestamp(executeUpdate());
2733  }
2734
2735  /**
2736   * Retrieves the value of a JDBC <code>DATALINK</code> parameter as a
2737   * <code>java.net.URL</code> object.
2738   *
2739   * @param parameterName the name of the parameter
2740   * @return the parameter value as a <code>java.net.URL</code> object in the
2741   * Java programming language. If the value was SQL <code>NULL</code>,
2742   * the value <code>null</code> is returned.
2743   * @exception SQLException if a database access error occurs, or if there is a
2744   * problem with the URL
2745   * @see #setURL
2746   * @since 1.4
2747   */

2748  public URL JavaDoc getURL(String JavaDoc parameterName) throws SQLException JavaDoc
2749  {
2750    if (!outAndNamedParameterTypes.containsKey(parameterName))
2751      throw new SQLException JavaDoc("Invalid named parameter " + parameterName);
2752
2753    try
2754    {
2755      return (URL JavaDoc) namedParameterValues.get(parameterName);
2756    }
2757    catch (Exception JavaDoc e)
2758    {
2759      throw new SQLException JavaDoc("Unable to convert named parameter "
2760          + parameterName + " to the requested type");
2761    }
2762  }
2763}
Popular Tags