KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.quadcap.jdbc;
2
3 /* Copyright 1999 - 2003 Quadcap Software. All rights reserved.
4  *
5  * This software is distributed under the Quadcap Free Software License.
6  * This software may be used or modified for any purpose, personal or
7  * commercial. Open Source redistributions are permitted. Commercial
8  * redistribution of larger works derived from, or works which bundle
9  * this software requires a "Commercial Redistribution License"; see
10  * http://www.quadcap.com/purchase.
11  *
12  * Redistributions qualify as "Open Source" under one of the following terms:
13  *
14  * Redistributions are made at no charge beyond the reasonable cost of
15  * materials and delivery.
16  *
17  * Redistributions are accompanied by a copy of the Source Code or by an
18  * irrevocable offer to provide a copy of the Source Code for up to three
19  * years at the cost of materials and delivery. Such redistributions
20  * must allow further use, modification, and redistribution of the Source
21  * Code under substantially the same terms as this license.
22  *
23  * Redistributions of source code must retain the copyright notices as they
24  * appear in each source code file, these license terms, and the
25  * disclaimer/limitation of liability set forth as paragraph 6 below.
26  *
27  * Redistributions in binary form must reproduce this Copyright Notice,
28  * these license terms, and the disclaimer/limitation of liability set
29  * forth as paragraph 6 below, in the documentation and/or other materials
30  * provided with the distribution.
31  *
32  * The Software is provided on an "AS IS" basis. No warranty is
33  * provided that the Software is free of defects, or fit for a
34  * particular purpose.
35  *
36  * Limitation of Liability. Quadcap Software shall not be liable
37  * for any damages suffered by the Licensee or any third party resulting
38  * from use of the Software.
39  */

40
41 import java.io.IOException JavaDoc;
42 import java.io.InputStream JavaDoc;
43 import java.io.Reader JavaDoc;
44
45 import java.util.Calendar JavaDoc;
46 import java.util.Vector JavaDoc;
47
48 import java.math.BigDecimal JavaDoc;
49
50 //#ifndef JDK11
51
import java.sql.Array JavaDoc;
52 import java.sql.Blob JavaDoc;
53 import java.sql.Clob JavaDoc;
54 import java.sql.Ref JavaDoc;
55 //#endif
56

57 import java.sql.Date JavaDoc;
58 import java.sql.SQLException JavaDoc;
59 import java.sql.SQLWarning JavaDoc;
60 import java.sql.Time JavaDoc;
61 import java.sql.Timestamp JavaDoc;
62 import java.sql.Types JavaDoc;
63
64 import antlr.RecognitionException;
65
66 import com.quadcap.sql.InsertBlob;
67 import com.quadcap.sql.ParameterExpression;
68 import com.quadcap.sql.SQLParser;
69 import com.quadcap.sql.Stmt;
70
71 import com.quadcap.io.AsciiReader;
72 import com.quadcap.io.ReaderInputStream;
73
74 import com.quadcap.sql.file.BlockFile;
75
76 import com.quadcap.sql.types.*;
77
78 import com.quadcap.util.Debug;
79
80 /**
81  * This class implements the <code>java.sql.PreparedStatement</code>
82  * interface, and provides facilities for execution of pre-compiled
83  * SQL statements. This release of QED performs all of the SQL parsing
84  * during the prepare phase, so that subsequent execution of the
85  * compiled statement is considerably faster than directly executing
86  * the statement using the <code>Statement</code> interface.
87  *
88  * @author Stan Bailes
89  */

90 public class PreparedStatement extends Statement
91     implements java.sql.PreparedStatement JavaDoc
92 {
93     Stmt stmt;
94     Vector JavaDoc params;
95     //#ifdef DEBUG
96
String JavaDoc sql;
97     //#endif
98

99     /**
100      * @deprecated in order to not appear in public javadoc
101      */

102     public PreparedStatement(Connection conn, String JavaDoc sql)
103     throws SQLException JavaDoc, IOException JavaDoc
104     {
105     super(conn);
106         //#ifdef DEBUG
107
this.sql = sql;
108     if (Statement.trace.bit(0)) {
109         Debug.println("prepare(" + sql + ")");
110         }
111         //#endif
112
session.makeTransaction();
113     SQLParser p = new SQLParser(session, sql, escapeProcessing);
114     String JavaDoc auth = qConn.getAuth();
115     try {
116         stmt = p.statement();
117             params = p.getParameters();
118     } catch (RecognitionException e) {
119         throw new SQLException JavaDoc(e.toString(), "42000");
120     } catch (antlr.TokenStreamException e) {
121         throw new SQLException JavaDoc(e.toString(), "Q0010");
122     } finally {
123         // XXX
124
// This is a hack. 'create schema' will temporarily set the
125
// 'auth' to the schema name, and this is the first place where
126
// we get a chance to restore the correct auth.
127
//
128
// This is made worse by the fact that names are resolved during
129
// the parse phase, and could be made better if antlr parser
130
// rules allowed you to specify a 'finally' handler.
131

132         // Also 'create schema' where the schema name is a parameter is
133
// going to fail badly.
134
qConn.setAuth(auth, null);
135     }
136     }
137     
138     /**
139      * This QED release doesn't support batch statement execution.
140      *
141      * @exception SQLException "not implemented"
142      */

143     public void addBatch() throws SQLException JavaDoc {
144     throw new SQLException JavaDoc("not implemented", "0A000");
145     }
146     
147     ParameterExpression getParam(int i) {
148     return (ParameterExpression)params.elementAt(i-1);
149     }
150     
151     /**
152      * Clear the values of any parameters to this prepared statement;
153      * i.e., set them all to <code>NULL</code>
154      *
155      * @exception SQLException may be thrown
156      */

157     public void clearParameters() throws SQLException JavaDoc {
158     for (int i = 1; i <= params.size(); i++) {
159         ParameterExpression pe = getParam(i);
160         pe.setValue(ValueNull.valueNull);
161     }
162     }
163     
164     /**
165      * Execute the current SQL statement, returning <code>true</code>
166      * if the statement generates a <code>ResultSet</code> object.
167      *
168      * @return true if execution of the statement results in the creation
169      * of a <code>ResultSet</code>
170      * @see #getResultSet()
171      * @exception SQLException may be thrown
172      */

173     public boolean execute() throws SQLException JavaDoc {
174         //#ifdef DEBUG
175
if (Statement.trace.bit(1)) {
176             Debug.println("PreparedStatement.execute(" + sql + ")");
177         }
178         //#endif
179
this.rs = null;
180     this.updateCount = -1;
181
182         if (this.qConn.isClosed()) {
183             throw new SQLException JavaDoc("Connection closed");
184         }
185     try {
186         session.doStatement(stmt);
187             this.rs = (ResultSet)session.getResultSet(this);
188             if (rs != null) {
189                 return true;
190             } else {
191                 this.updateCount = session.getUpdateCount();
192                 return false;
193             }
194     } catch (IOException JavaDoc e) {
195         try {
196         session.endStatement(true);
197         } catch (IOException JavaDoc e1) {}
198         throw new SQLException JavaDoc(e.toString(), "Q0011");
199     } catch (SQLException JavaDoc e) {
200         try {
201         session.endStatement(true);
202         } catch (IOException JavaDoc e1) {}
203         throw e;
204     } catch (Throwable JavaDoc e) {
205         Debug.print(e);
206         try {
207         session.endStatement(true);
208         } catch (IOException JavaDoc e1) {}
209         throw new SQLException JavaDoc(e.toString(), "Q0013");
210     }
211     }
212     
213     /**
214      * Execute the prepared SQL query statement, returning the
215      * <code>ResultSet</code> object containing the results of the
216      * query.
217      *
218      * @return a <code>ResultSet</code> object containing the results of
219      * the query
220      * @exception SQLException may be thrown
221      */

222     public java.sql.ResultSet JavaDoc executeQuery() throws SQLException JavaDoc {
223     if (execute()) {
224         return this.rs;
225     } else {
226         return null;
227     }
228     }
229     
230     /**
231      * Execute the prepared SQL update statement, returning the update
232      * count, meaning the number of rows updated or inserted by this
233      * statement.
234      *
235      * @return the update count
236      * @exception SQLException may be thrown
237      */

238     public int executeUpdate() throws SQLException JavaDoc {
239     if (!execute()) {
240         return updateCount;
241     } else {
242         return 0;
243     }
244     }
245     
246     /**
247      * QED doesn't implement this feature, which requires information
248      * about the <code>ResultSet</code> that will be generated by this
249      * <code>PreparedStatement</code> object when it is executed.
250      * Instead, first call <code>execute()</code> or
251      * <code>executeQuery()</code>, then call
252      * <code>ResultSet.getMetaData()</code> on the
253      * <code>ResultSet</code> object that is returned.
254      *
255      * @return null
256      */

257     public java.sql.ResultSetMetaData JavaDoc getMetaData() {
258     return null;
259     }
260     
261     /**
262      * Set the statement parameter to the specified character value using an
263      * <code>InputStream</code> that contains a stream of ASCII bytes.
264      * The ASCII bytes are converted to Unicode character values before
265      * being inserted into the database.
266      *
267      * @param col the parameter index
268      * @param is an input stream containing ASCII bytes.
269      * @param length the number of bytes to read from the stream
270      * @return an <code>InputStream</code>
271      * @exception SQLException may be thrown
272      */

273     public void setAsciiStream(int col, InputStream JavaDoc in, int length)
274     throws SQLException JavaDoc
275     {
276         try {
277             if (in == null) {
278                 setParamValue(col, ValueNull.valueNull);
279             } else {
280                 ValueClob clob = new ValueClob(session.getDatabase(),
281                                                session.makeTransaction(),
282                                                new AsciiReader(in), length);
283                 setParamValue(col, clob);
284                 session.doStep(new InsertBlob(session, clob));
285                 clob.close();
286             }
287         
288     } catch (IOException JavaDoc e) {
289         Debug.print(e);
290         throw new SQLException JavaDoc(e.toString(), "Q001H");
291     }
292     }
293
294     final void setParamValue(int col, Value v) throws SQLException JavaDoc {
295         //#ifdef DEBUG
296
if (Statement.trace.bit(4)) {
297         Debug.println("setValue(" + col + ", " + v + ")");
298         }
299         //#endif
300
getParam(col).setValue(v);
301     }
302     
303     /**
304      * Set the statement parameter to the specified
305      * <code>BigDecimal</code> value.
306      *
307      * @param col the parameter index
308      * @param val the new value
309      * @exception SQLException may be thrown
310      */

311     public void setBigDecimal(int col, BigDecimal JavaDoc val) throws SQLException JavaDoc {
312         if (val == null) {
313             setParamValue(col, ValueNull.valueNull);
314         } else {
315             setParamValue(col, new ValueScaledInteger(val));
316         }
317     }
318     
319     /**
320      * Set the statement parameter to the specified binary value using an
321      * <code>InputStream</code> that contains a stream of bytes.
322      *
323      * @param col the parameter index
324      * @param is an input stream containing ASCII bytes.
325      * @param length the number of bytes to read from the stream
326      * <p>
327      * If 'length &gt; 0', then the blob's length will be set to the value
328      * of the 'length' parameter.
329      * <p>
330      * If 'length &lt; 0', then the blob's length will be set to the number
331      * of bytes read.
332      * @return an <code>InputStream</code>
333      * @exception SQLException may be thrown
334      */

335     public void setBinaryStream(int col, InputStream JavaDoc in, int length)
336     throws SQLException JavaDoc
337     {
338     try {
339             if (in == null) {
340                 setParamValue(col, ValueNull.valueNull);
341             } else {
342                 ValueBlob blob = new ValueBlob(session.getDatabase(),
343                                                session.makeTransaction(),
344                                                in, length);
345                 setParamValue(col, blob);
346                 session.doStep(new InsertBlob(session, blob));
347                 blob.close();
348             }
349         
350     } catch (IOException JavaDoc e) {
351         Debug.print(e);
352         throw new SQLException JavaDoc(e.toString(), "Q001H");
353     }
354     }
355     
356     /**
357      * Set the statement parameter to the specified
358      * <code>boolean</code> value.
359      *
360      * @param col the parameter index
361      * @param val the new value
362      * @exception SQLException may be thrown
363      */

364     public void setBoolean(int col, boolean val) throws SQLException JavaDoc {
365     setParamValue(col, new ValueBoolean(val));
366     }
367     
368     /**
369      * Set the statement parameter to the specified
370      * <code>byte</code> value.
371      *
372      * @param col the parameter index
373      * @param val the new value
374      * @exception SQLException may be thrown
375      */

376     public void setByte(int col, byte val) throws SQLException JavaDoc {
377     setParamValue(col, new ValueShort(val));
378     }
379     
380     /**
381      * Set the statement parameter to the specified
382      * <code>byte</code> array value.
383      *
384      * @param col the parameter index
385      * @param val the new value
386      * @exception SQLException may be thrown
387      */

388     public void setBytes(int col, byte[] val) throws SQLException JavaDoc {
389         if (val == null) {
390             setParamValue(col, ValueNull.valueNull);
391         } else {
392             setParamValue(col, new ValueOctets(val));
393         }
394     }
395     
396     /**
397      * Set the statement parameter to the specified character value using a
398      * <code>Reader</code> that contains a stream of Unicode characters.
399      *
400      * @param col the parameter index
401      * @param r a reader containing the value's characters.
402      * @param length the number of bytes to read from the stream
403      * @return an <code>InputStream</code>
404      * @exception SQLException may be thrown
405      */

406     public void setCharacterStream(int col, Reader JavaDoc r, int length)
407     throws SQLException JavaDoc
408     {
409     try {
410             if (r == null) {
411                 setParamValue(col, ValueNull.valueNull);
412             } else {
413                 ValueClob clob = new ValueClob(session.getDatabase(),
414                                                session.makeTransaction(),
415                                                r, length);
416                 setParamValue(col, clob);
417                 session.doStep(new InsertBlob(session, clob));
418                 clob.close();
419             }
420         
421     } catch (IOException JavaDoc e) {
422         Debug.print(e);
423         throw new SQLException JavaDoc(e.toString(), "Q001H");
424     }
425     }
426     
427     /**
428      * Set the statement parameter to the specified
429      * <code>Date</code> value.
430      *
431      * @param col the parameter index
432      * @param val the new value
433      * @exception SQLException may be thrown
434      */

435     public void setDate(int col, Date JavaDoc val) throws SQLException JavaDoc {
436         if (val == null) {
437             setParamValue(col, ValueNull.valueNull);
438         } else {
439             setParamValue(col, new ValueDate(val.getTime()));
440         }
441     }
442     
443     /**
444      * Set the statement parameter to the specified
445      * <code>Date</code> value.
446      *
447      * @param col the parameter index
448      * @param val the new value
449      * @param cal a <code>Calendar<code> object that is used for converting
450      * the database date to the local timezone. The database date is
451      * adjusted based on the <code>Calendar</code> timezone and DST offset.
452      * @exception SQLException may be thrown
453      */

454     public void setDate(int col, Date JavaDoc val, Calendar JavaDoc cal) throws SQLException JavaDoc {
455         if (val == null) {
456             setParamValue(col, ValueNull.valueNull);
457         } else {
458             cal.setTime(val);
459             setParamValue(col, new ValueDate(cal.getTime().getTime()));
460         }
461     }
462     
463     /**
464      * Set the statement parameter to the specified
465      * <code>double</code> value.
466      *
467      * @param col the parameter index
468      * @param val the new value
469      * @exception SQLException may be thrown
470      */

471     public void setDouble(int col, double val) throws SQLException JavaDoc {
472     setParamValue(col, new ValueDouble(val));
473     }
474     
475     /**
476      * Set the statement parameter to the specified
477      * <code>float</code> value.
478      *
479      * @param col the parameter index
480      * @param val the new value
481      * @exception SQLException may be thrown
482      */

483     public void setFloat(int col, float val) throws SQLException JavaDoc {
484     setParamValue(col, new ValueDouble(val));
485     }
486     
487     /**
488      * Set the statement parameter to the specified
489      * <code>int</code> value.
490      *
491      * @param col the parameter index
492      * @param val the new value
493      * @exception SQLException may be thrown
494      */

495     public void setInt(int col, int val) throws SQLException JavaDoc {
496     setParamValue(col, new ValueInteger(val));
497     }
498     
499     /**
500      * Set the statement parameter to the specified
501      * <code>long</code> value.
502      *
503      * @param col the parameter index
504      * @param val the new value
505      * @exception SQLException may be thrown
506      */

507     public void setLong(int col, long val) throws SQLException JavaDoc {
508     setParamValue(col, new ValueLong(val));
509     }
510     
511     /**
512      * Set the statement parameter to the specified
513      * <code>null</code> value.
514      *
515      * @param col the parameter index
516      * @param type the JDBC type of the parameter. This is ignored by QED
517      * because a null is a null is a null.
518      * @exception SQLException may be thrown
519      */

520     public void setNull(int col, int type) throws SQLException JavaDoc {
521     setParamValue(col, ValueNull.valueNull);
522     }
523     
524     /**
525      * Set the statement parameter to the specified
526      * <code>null</code> value.
527      *
528      * @param col the parameter index
529      * @param type the JDBC type of the parameter. This is ignored by QED
530      * because a null is a null is a null.
531      * @param typename the fully qualified type name of the parameter.
532      * This is ignored by QED
533      * because a null is a null is a null.
534      * @exception SQLException may be thrown
535      */

536     public void setNull(int col, int type, String JavaDoc typename)
537     throws SQLException JavaDoc
538     {
539     setParamValue(col, ValueNull.valueNull);
540     }
541     
542     /**
543      * Set the statement parameter to the specified
544      * <code>Object</code> value.
545      *
546      * @param col the parameter index
547      * @param val the new value
548      * @exception SQLException may be thrown
549      */

550     public void setObject(int col, Object JavaDoc val) throws SQLException JavaDoc {
551         if (val instanceof Blob JavaDoc) {
552             Blob JavaDoc blob = (Blob JavaDoc)val;
553             setBinaryStream(col, blob.getBinaryStream(), (int)blob.length());
554         } else if (val instanceof Clob JavaDoc) {
555             Clob JavaDoc clob = (Clob JavaDoc)val;
556             setCharacterStream(col, clob.getCharacterStream(),
557                                (int)clob.length());
558         } else {
559             setParamValue(col, Value.fromObject(val));
560         }
561     }
562     
563     /**
564      * Set the statement parameter to the specified
565      * <code>Object</code> value.
566      *
567      * @param col the parameter index
568      * @param val the new value
569      * @param type the JDBC type of the parameter.
570      * @exception SQLException may be thrown
571      */

572     public void setObject(int col, Object JavaDoc val, int type) throws SQLException JavaDoc {
573     Type t = Value.typeForJdbcType(type);
574     Value v = Value.fromObject(val);
575     setParamValue(col, t.convert(v));
576     }
577     
578     /**
579      * Set the statement parameter to the specified
580      * <code>Object</code> value.
581      *
582      * @param col the parameter index
583      * @param val the new value
584      * @param type the JDBC type of the parameter.
585      * @param scale for numeric types, the precision of the value.
586      * @exception SQLException may be thrown
587      */

588     public void setObject(int col, Object JavaDoc val, int type, int scale)
589     throws SQLException JavaDoc
590     {
591     Value v = Value.fromObject(val);
592     Type t = null;
593     switch (type) {
594     case Types.NUMERIC:
595     case Types.DECIMAL:
596         t = new TypeDecimal(32, scale);
597             break;
598     default:
599         t = Value.typeForJdbcType(type);
600     }
601     setParamValue(col, t.convert(v));
602     }
603     
604     /**
605      * Set the statement parameter to the specified
606      * <code>short</code> value.
607      *
608      * @param col the parameter index
609      * @param val the new value
610      * @exception SQLException may be thrown
611      */

612     public void setShort(int col, short val) throws SQLException JavaDoc {
613     setParamValue(col, new ValueShort(val));
614     }
615     
616     /**
617      * Set the statement parameter to the specified
618      * <code>String</code> value.
619      *
620      * @param col the parameter index
621      * @param val the new value
622      * @exception SQLException may be thrown
623      */

624     public void setString(int col, String JavaDoc val) throws SQLException JavaDoc {
625         if (val == null) {
626             setParamValue(col, ValueNull.valueNull);
627         } else {
628             setParamValue(col, new ValueString(val));
629         }
630     }
631     
632     /**
633      * Set the statement parameter to the specified
634      * <code>Time</code> value.
635      *
636      * @param col the parameter index
637      * @param val the new value
638      * @exception SQLException may be thrown
639      */

640     public void setTime(int col, Time JavaDoc val) throws SQLException JavaDoc {
641         if (val == null) {
642             setParamValue(col, ValueNull.valueNull);
643         } else {
644             setParamValue(col, new ValueTime(val.getTime()));
645         }
646     }
647     
648     /**
649      * Set the statement parameter to the specified
650      * <code>Time</code> value.
651      *
652      * @param col the parameter index
653      * @param val the new value
654      * @param cal a <code>Calendar<code> object that is used for converting
655      * the database date to the local timezone. The database date is
656      * adjusted based on the <code>Calendar</code> timezone and DST offset.
657      * @exception SQLException may be thrown
658      */

659     public void setTime(int col, Time JavaDoc val, Calendar JavaDoc cal) throws SQLException JavaDoc {
660         if (val == null) {
661             setParamValue(col, ValueNull.valueNull);
662         } else {
663             long t = val.getTime();
664             cal.setTime(val);
665             t -= (cal.get(Calendar.ZONE_OFFSET) +
666                   cal.get(Calendar.DST_OFFSET));
667             setParamValue(col, new ValueTime(t));
668         }
669     }
670     
671     /**
672      * Set the statement parameter to the specified
673      * <code>Timestamp</code> value.
674      *
675      * @param col the parameter index
676      * @param val the new value
677      * @exception SQLException may be thrown
678      */

679     public void setTimestamp(int col, Timestamp JavaDoc val) throws SQLException JavaDoc {
680         if (val == null) {
681             setParamValue(col, ValueNull.valueNull);
682         } else {
683             setParamValue(col, new ValueTimestamp(val));
684         }
685     }
686     
687     /**
688      * Set the statement parameter to the specified
689      * <code>Timestamp</code> value.
690      *
691      * @param col the parameter index
692      * @param val the new value
693      * @param cal a <code>Calendar<code> object that is used for converting
694      * the database date to the local timezone. The database date is
695      * adjusted based on the <code>Calendar</code> timezone and DST offset.
696      * @exception SQLException may be thrown
697      */

698     public void setTimestamp(int col, Timestamp JavaDoc val, Calendar JavaDoc cal)
699     throws SQLException JavaDoc
700     {
701         if (val == null) {
702             setParamValue(col, ValueNull.valueNull);
703         } else {
704             long t = val.getTime();
705             cal.setTime(val);
706             t -= (cal.get(Calendar.ZONE_OFFSET) +
707                   cal.get(Calendar.DST_OFFSET));
708             Timestamp JavaDoc r = new Timestamp JavaDoc(t);
709             r.setNanos(val.getNanos());
710             setParamValue(col, new ValueTimestamp(r));
711         }
712     }
713
714     /**
715      * @deprecated
716      */

717     public void setUnicodeStream(int col, InputStream JavaDoc in, int length)
718     throws SQLException JavaDoc
719     {
720     setBinaryStream(col, in, length);
721     }
722
723
724     /**
725      * @deprecated
726      */

727     public PreparedStatement(Connection conn, String JavaDoc sql,
728                  int resultSetType,
729                  int resultSetConcurrency)
730     throws SQLException JavaDoc, IOException JavaDoc
731     {
732     this(conn, sql);
733     this.resultSetType = resultSetType;
734     this.resultSetConcurrency = resultSetConcurrency;
735     }
736     
737    //#ifndef JDK11
738
/**
739      * Set the statement parameter to the specified
740      * <code>ARRAY</code> value.
741      * This QED release doesn't support ARRAY types, so a
742      * "not implemented" exception is thrown
743      *
744      * @param col the parameter index
745      * @param val the new value
746      * @exception SQLException "not implemented"
747      */

748     public void setArray(int col, Array JavaDoc val) throws SQLException JavaDoc {
749     throw new SQLException JavaDoc("not implemented", "0A000");
750     }
751
752     /**
753      * Set the statement parameter to the specified
754      * <code>Blob</code> value.
755      *
756      * @param col the parameter index
757      * @param val the new value
758      * @exception SQLException may be thrown
759      */

760     public void setBlob(int col, Blob JavaDoc val) throws SQLException JavaDoc {
761         if (val == null) {
762             setParamValue(col, ValueNull.valueNull);
763         } else {
764             if (val instanceof ValueBlob) {
765                 setParamValue(col, (ValueBlob)val);
766             } else {
767                 setBinaryStream(col, val.getBinaryStream(),
768                                 (int)(val.length()));
769             }
770         }
771     }
772     
773     /**
774      * Set the statement parameter to the specified
775      * <code>Clob</code> value.
776      *
777      * @param col the parameter index
778      * @param val the new value
779      * @exception SQLException may be thrown
780      */

781     public void setClob(int col, Clob JavaDoc val) throws SQLException JavaDoc {
782         if (val == null) {
783             setParamValue(col, ValueNull.valueNull);
784         } else {
785             setAsciiStream(col, val.getAsciiStream(), (int)(val.length()));
786         }
787     }
788     
789     /**
790      * Set the statement parameter to the specified
791      * <code>REF</code> value.
792      * This QED release doesn't support ARRAY types, so a
793      * "not implemented" exception is thrown
794      *
795      * @param col the parameter index
796      * @param val the new value
797      * @exception SQLException "not implemented"
798      */

799     public void setRef(int col, Ref JavaDoc val) throws SQLException JavaDoc {
800     throw new SQLException JavaDoc("not implemented", "0A000");
801     }
802     
803     //#endif
804

805     //------------------------- JDBC 3.0 -----------------------------------
806
//#ifdef JDK14
807

808     /**
809      * Sets the designated parameter to the given <code>java.net.URL</code>
810      * value.
811      * The driver converts this to an SQL <code>DATALINK</code> value
812      * when it sends it to the database.
813      *
814      * <p>QED simply converts the URL to a string</p>
815      *
816      * @param parameterIndex the first parameter is 1, the second is 2, ...
817      * @param x the <code>java.net.URL</code> object to be set
818      * @exception SQLException if a database access error occurs
819      * @since 1.4
820      */

821     public void setURL(int parameterIndex, java.net.URL JavaDoc x)
822         throws SQLException JavaDoc
823     {
824         setString(parameterIndex, x.toString());
825     }
826     
827
828     /**
829      * Retrieves the number, types and properties of this
830      * <code>PreparedStatement</code> object's parameters.
831      *
832      * <p><i>QED: Not implemented</i></p>
833      *
834      * @return a <code>ParameterMetaData</code> object that contains information
835      * about the number, types and properties of this
836      * <code>PreparedStatement</code> object's parameters
837      * @exception SQLException if a database access error occurs
838      * @see ParameterMetaData
839      * @since 1.4
840      */

841     public java.sql.ParameterMetaData JavaDoc getParameterMetaData()
842         throws SQLException JavaDoc
843     {
844         throw new SQLException JavaDoc("Not implemented");
845     }
846     //#endif
847

848     public String JavaDoc toString() {
849         StringBuffer JavaDoc sb =
850             new StringBuffer JavaDoc("com.quadcap.jdbc.PreparedStatement(");
851         if (params != null) for (int i = 1; i <= params.size(); i++) {
852             if (i > 1) sb.append(",");
853             ParameterExpression e = getParam(i);
854             Value v = e.getValue(null, null);
855             sb.append(String.valueOf(v));
856         }
857         sb.append(")");
858         return sb.toString();
859     }
860         
861 }
862
Popular Tags