KickJava   Java API By Example, From Geeks To Geeks.

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


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
43 import java.util.Map JavaDoc;
44
45 import java.sql.CallableStatement JavaDoc;
46 import java.sql.ResultSet JavaDoc;
47 //#ifdef JDK14
48
import java.sql.Savepoint JavaDoc;
49 //#endif
50
import java.sql.SQLException JavaDoc;
51 import java.sql.SQLWarning JavaDoc;
52
53 import com.quadcap.sql.Database;
54 import com.quadcap.sql.DbException;
55 import com.quadcap.sql.Session;
56
57 import com.quadcap.util.ConfigNumber;
58 import com.quadcap.util.Debug;
59 import com.quadcap.util.Util;
60
61 /**
62  * This class implements the <code>java.sql.Connection</code> interface,
63  * which provides facilities for executing SQL statements, performing
64  * transaction commit and rollback, and obtaining information about
65  * the database via <code>DatabaseMetaData</code>.
66  *
67  * @author Stan Bailes
68  */

69 public class Connection implements java.sql.Connection JavaDoc {
70     /*{com.quadcap.qed.Trace-vars.xml-1052}
71      * <config-var>
72      * <config-name>qed.trace.Connection</config-name>
73      * <config-dflt>0</config-dflt>
74      * <config-desc>
75      * <pre>
76      * bit 0: Connection lifecycle
77      * bit 1: Connection methods
78      * </pre>
79      * </config-desc>
80      * </config-var>
81      */

82
83     //#ifdef DEBUG
84
static final ConfigNumber trace =
85     ConfigNumber.find("qed.trace.Connection", "0");
86     //#endif
87

88     Database db;
89     com.quadcap.sql.Connection qConn = null;
90     boolean closed = false;
91     Map JavaDoc typeMap = null;
92
93     /**
94      * Construct a new connection object for the specified database
95      * and userid.
96      * @deprecated <i>Pay no attention to that man behind the curtains.</i>
97      *
98      * @param db the database
99      * @param auth the userid
100      * @param passwd the password
101      */

102     public Connection(Database db, String JavaDoc auth, String JavaDoc passwd)
103         throws SQLException JavaDoc
104     {
105     this.db = db;
106     if (auth == null) auth = "";
107     this.qConn = new com.quadcap.sql.Connection(db, auth.toUpperCase(),
108                                                     passwd);
109         //#ifdef DEBUG
110
if (trace.bit(0)) {
111             Debug.println("Connection.init(" + qConn + ")");
112         }
113         //#endif
114
}
115
116     /**
117      * Return the database to which this connection is bound.
118      * @deprecated <i>Pay no attention to that man behind the curtains.</i>
119      *
120      * @return the connection's database
121      */

122     public Database getDatabase() {
123     return db;
124     }
125
126     /**
127      * Return the connection's session.
128      * @deprecated <i>Pay no attention to that man behind the curtains.</i>
129      *
130      * @return the connection's session
131      */

132     public final com.quadcap.sql.Connection getConnection() {
133     return qConn;
134     }
135
136     //------------------------------------------------------------------
137
// java.sql.Connection implementation
138
//------------------------------------------------------------------
139

140     /**
141      * Clears all warnings that have been reported on calls to this
142      * connection. QED doesn't currently throw any SQLWarnings,
143      * so this operation does nothing.
144      */

145     public void clearWarnings() {
146     }
147     
148     /**
149      * Close this connection, which implicitly ends (i.e., commits) any
150      * pending transactions for this connection, closes any
151      * <code>ResultSet</code>s opened on this connection, and marks
152      * the connection as closed. It is an error to attempt to use
153      * this connection after the close operation
154      *
155      * @exception SQLException may be thrown
156      */

157     public void close() throws SQLException JavaDoc {
158         //#ifdef DEBUG
159
if (trace.bit(0)) {
160             Debug.println("Connection[" + qConn + "].close()");
161         }
162         //#endif
163
closed = true;
164         try {
165             if (qConn != null) qConn.close();
166         } catch (IOException JavaDoc e) {
167             throw DbException.wrapThrowable(e);
168         } finally {
169             qConn = null;
170         }
171     }
172             
173     /**
174      * Make sure the connection closes on gc...
175      */

176     public void finalize() throws Throwable JavaDoc {
177         if (!closed) {
178             try {
179                 close();
180             } catch (Throwable JavaDoc t) {}
181         }
182         super.finalize();
183     }
184
185     /**
186      * Commit any pending changes for the current transaction. This
187      * ends the transaction; any further statements executed by this
188      * connection will cause a new transaction to be started. This
189      * method closes any <code>ResultSet</code>s opened on this connection.
190      *
191      * @exception SQLException may be thrown
192      */

193     public void commit() throws SQLException JavaDoc {
194         //#ifdef DEBUG
195
if (trace.bit(1)) {
196             Debug.println("Connection.commit()");
197         }
198         //#endif
199
if (closed) throw new SQLException JavaDoc("Connection closed", "08003");
200     try {
201         qConn.endTransaction();
202     } catch (IOException JavaDoc e) {
203         throw DbException.wrapThrowable(e);
204     }
205     }
206     
207     /**
208      * Return a new <code>Statement</code> object that can be used to
209      * execute SQL statements on this connection
210      *
211      * @return a new <code>Statement</code> object
212      * @exception SQLException may be thrown
213      */

214     public java.sql.Statement JavaDoc createStatement() throws SQLException JavaDoc {
215     if (closed) throw new SQLException JavaDoc("Connection closed", "08003");
216         try {
217             return new Statement(this);
218         } catch (IOException JavaDoc e) {
219             throw DbException.wrapThrowable(e);
220         }
221     }
222     
223     /**
224      * Return the current value for the <code>autoCommit</code> variable.
225      * By default, connections are created with <code>autoCommit</code>
226      * equal to <code>true</code>
227      *
228      * @return the current <code>autoCommit</code> state
229      */

230     public boolean getAutoCommit() throws SQLException JavaDoc {
231     if (closed) throw new SQLException JavaDoc("Connection closed", "08003");
232     return qConn.getAutoCommit();
233     }
234     
235     /**
236      * QED doesn't support catalogs, so this function returns
237      * <code>null</code>
238      *
239      * @return null
240      */

241     public String JavaDoc getCatalog() {
242     return null;
243     }
244     
245     /**
246      * Return a <code>DatabaseMetaData</code> object that can be used
247      * to get information about the features supported by QED.
248      *
249      * @return a <code>DatabaseMetaData</code>
250      */

251     DatabaseMetaData dbm = null;
252     public java.sql.DatabaseMetaData JavaDoc getMetaData() throws SQLException JavaDoc {
253         try {
254             if (dbm == null) {
255                 dbm = new DatabaseMetaData(this);
256             }
257         } catch (IOException JavaDoc e) {
258             throw DbException.wrapThrowable(e);
259         }
260         return dbm;
261     }
262     
263     /**
264      * Return the current transaction isolation level -- QED currently
265      * only supports <code>TRANSACTION_SERIALIZABLE</code>
266      *
267      * @return <code>TRANSACTION_SERIALIZABLE</code>
268      */

269     public int getTransactionIsolation() {
270     return TRANSACTION_SERIALIZABLE;
271     }
272     
273     /**
274      * QED doesn't generate any <code>SQLWarning</code>s, so this function
275      * always returns <code>null</code>
276      *
277      * @return null
278      */

279     public SQLWarning JavaDoc getWarnings() {
280     return null;
281     }
282     
283     /**
284      * Return true if this connection has been closed.
285      *
286      * @return true if this connection has been closed.
287      */

288     public boolean isClosed() {
289     return closed;
290     }
291     
292     /**
293      * Return true if this connection is read only. QED doesn't currently
294      * support read-only connections, so this always returns
295      * false
296      *
297      * @return false
298      */

299     public boolean isReadOnly() {
300     return false;
301     }
302     
303     /**
304      * This function is supposed to translate the specified query into
305      * the native query language of the underlying DBMS. In QED, the
306      * native query language is SQL-92, and JDBC escapes are directly
307      * supported by the DBMS, so this translation is a no-op, and always
308      * returns the original string
309      *
310      * @param stmt an SQL statement
311      * @return the same SQL statement
312      */

313     public String JavaDoc nativeSQL(String JavaDoc stmt) {
314     return stmt;
315     }
316     
317     /**
318      * QED doesn't support stored procedures, so this method returns
319      * a "not implemented" exception
320      *
321      * @param sql the SQL statement
322      * @return never
323      * @exception SQLException "not implemented"
324      */

325     public CallableStatement JavaDoc prepareCall(String JavaDoc sql) throws SQLException JavaDoc {
326     throw new SQLException JavaDoc("Not implemented");
327     }
328     
329     /**
330      * QED doesn't support stored procedures, so this method returns
331      * a "not implemented" exception
332      *
333      * @param sql the SQL statement
334      * @param resultType the desired <code>ResultSet</code> type
335      * @param resultSetConcurrency the desired <code>ResultSet</code>
336      * concurrency
337      * @return never
338      * @exception SQLException "not implemented"
339      */

340     public CallableStatement JavaDoc prepareCall(String JavaDoc sql, int resultType,
341                      int resultSetConcurrency)
342     throws SQLException JavaDoc
343     {
344     throw new SQLException JavaDoc("Not implemented");
345     }
346     
347     /**
348      * Returns a new <code>PreparedStatement</code> statement, which is
349      * a pre-compiled representation of the statement <i>sql</i>, with
350      * place holders for parameters specified using the <code>'?'</code>
351      * character.
352      *
353      * @param sql the SQL statement
354      * @return the <code>PreparedStatement</code> statement that can be
355      * used to invoke the SQL statement, after the parameters
356      * represented by the <code>'?'</code> characters are
357      * supplied
358      * @exception SQLException may be thrown
359      */

360     public java.sql.PreparedStatement JavaDoc prepareStatement(String JavaDoc sql)
361     throws SQLException JavaDoc
362     {
363     if (closed) throw new SQLException JavaDoc("Connection closed", "08003");
364         try {
365             return new PreparedStatement(this, sql);
366         } catch (IOException JavaDoc e) {
367             throw DbException.wrapThrowable(e);
368         }
369     }
370     
371     /**
372      * Returns a new <code>PreparedStatement</code> statement, which is
373      * a pre-compiled representation of the statement <i>sql</i>, with
374      * place holders for parameters specified using the <code>'?'</code>
375      * character.
376      *
377      * @param sql the SQL statement
378      * @param resultType the desired <code>ResultSet</code> type
379      * @param resultSetConcurrency the desired <code>ResultSet</code>
380      * concurrency
381      * @return the <code>PreparedStatement</code> statement that can be
382      * used to invoke the SQL statement, after the parameters
383      * represented by the <code>'?'</code> characters are
384      * supplied
385      * @exception SQLException may be thrown
386      */

387     public java.sql.PreparedStatement JavaDoc prepareStatement(String JavaDoc sql,
388                                int resultType,
389                                int resultSetConcurrency)
390     throws SQLException JavaDoc
391     {
392     if (closed) throw new SQLException JavaDoc("Connection closed", "08003");
393         try {
394             return new PreparedStatement(this, sql, resultType,
395                                          resultSetConcurrency);
396         } catch (IOException JavaDoc e) {
397             throw DbException.wrapThrowable(e);
398         }
399     }
400     
401     /**
402      * Roll back any pending changes for the current transaction. This
403      * ends the transaction; any further statements executed by this
404      * connection will cause a new transaction to be started. This
405      * method closes any <code>ResultSet</code>s opened on this connection.
406      *
407      * @exception SQLException may be thrown
408      */

409     public void rollback() throws SQLException JavaDoc {
410         //#ifdef DEBUG
411
if (trace.bit(1)) {
412             Debug.println("Connection.rollback()");
413         }
414         //#endif
415
if (closed) {
416         throw new SQLException JavaDoc("Connection closed", "08003");
417     }
418     try {
419         qConn.rollbackTransaction();
420     } catch (IOException JavaDoc e) {
421         throw DbException.wrapThrowable(e);
422     }
423     }
424     
425     /**
426      * Set the state of the <code>autoCommit</code> flag.
427      *
428      * @param autoCommit the new <code>autoCommit</code> state.
429      */

430     public void setAutoCommit(boolean autoCommit) throws SQLException JavaDoc {
431         //#ifdef DEBUG
432
if (trace.bit(1)) {
433             Debug.println("Connection.setAutoCommit(" + autoCommit + ")");
434         }
435         //#endif
436
if (closed) throw new SQLException JavaDoc("Connection closed", "08003");
437     qConn.setAutoCommit(autoCommit);
438     }
439     
440     /**
441      * QED doesn't support catalogs, so this function throws
442      * a "not implemented" exception
443      *
444      * @exception SQLException "not implemented"
445      */

446     public void setCatalog(String JavaDoc catalog) throws SQLException JavaDoc {
447     throw new SQLException JavaDoc("Not implemented");
448     }
449     
450     /**
451      * QED doesn't support read-only connections, so this function will
452      * throw a "not implemented" exception if it is called with
453      * <code>readOnly == true</code>
454      *
455      * @param readOnly had better be false
456      * @exception SQLException if it's not
457      */

458     public void setReadOnly(boolean readOnly) throws SQLException JavaDoc {
459     if (readOnly) {
460         throw new SQLException JavaDoc("Read-only connections not supported");
461     }
462     }
463     
464     /**
465      * QED only supports the <code>TRANSACTION_SERIALIZABLE</code>
466      * isolation level, so this function will
467      * throw a "not implemented" exception if it is called with
468      * any other value.
469      *
470      * @param readOnly had better be <code>TRANSACTION_SERIALIZABLE</code>
471      * @exception SQLException if it's not
472      */

473     public void setTransactionIsolation(int trans) throws SQLException JavaDoc {
474     if (trans != TRANSACTION_SERIALIZABLE) {
475         throw new SQLException JavaDoc("Transaction isolation " + trans +
476                    " not supported");
477     }
478
479     }
480
481     //#ifndef JDK11
482
/**
483      * Set the type map to be used for custom type mapping of UDTS.
484      * In this release of QED, this call will succeed, but type mapping
485      * is not fully implemented in this release.
486      *
487      * @param map the new map
488      */

489     public void setTypeMap(Map JavaDoc map) throws SQLException JavaDoc {
490     this.typeMap = map;
491     }
492
493     /**
494      * Return the current type map to be used for custom type mapping of UDTS.
495      * In this release of QED, this call will succeed, but type mapping
496      * is not fully implemented in this release.
497      *
498      * @return the curren type map
499      */

500     public Map JavaDoc getTypeMap() throws SQLException JavaDoc {
501     return typeMap;
502     }
503
504     /**
505      * Return a new <code>Statement</code> object that can be used to
506      * execute SQL statements on this connection
507      *
508      * @param resultType the desired <code>ResultSet</code> type
509      * @param resultSetConcurrency the desired <code>ResultSet</code>
510      * concurrency
511      * @return a new <code>Statement</code> object
512      * @exception SQLException may be thrown
513      */

514     public java.sql.Statement JavaDoc createStatement(int resultType,
515                           int resultSetConcurrency)
516     throws SQLException JavaDoc
517     {
518     if (closed) throw new SQLException JavaDoc("Connection closed", "08003");
519         try {
520             return new Statement(this, resultType, resultSetConcurrency);
521         } catch (IOException JavaDoc e) {
522             throw DbException.wrapThrowable(e);
523         }
524     }
525     
526     //#endif
527

528
529     //--------------------------JDBC 3.0-----------------------------
530

531     //#ifdef JDK14
532
/**
533      * Changes the holdability of <code>ResultSet</code> objects
534      * created using this <code>Connection</code> object to the given
535      * holdability.
536      *
537      * <p>QED: <code>ResultSet</code>s are always closed on commit.</p>
538      *
539      * @param holdability a <code>ResultSet</code> holdability constant; one of
540      * <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
541      * <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
542      * @throws SQLException if a database access occurs, the given parameter
543      * is not a <code>ResultSet</code> constant indicating holdability,
544      * or the given holdability is not supported
545      * @see #getHoldability
546      * @see ResultSet
547      * @since 1.4
548      */

549     public void setHoldability(int holdability) throws SQLException JavaDoc {
550         if (holdability != ResultSet.CLOSE_CURSORS_AT_COMMIT) {
551             throw new SQLException JavaDoc("Not implemented");
552         }
553     }
554
555     /**
556      * Retrieves the current holdability of <code>ResultSet</code> objects
557      * created using this <code>Connection</code> object.
558      *
559      * <p>QED: <code>ResultSet</code>s are always closed on commit.</p>
560      *
561      * @return the holdability, one of
562      * <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
563      * <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
564      * @throws SQLException if a database access occurs
565      * @see #setHoldability
566      * @see ResultSet
567      * @since 1.4
568      */

569     public int getHoldability() throws SQLException JavaDoc {
570         return ResultSet.CLOSE_CURSORS_AT_COMMIT;
571     }
572
573     /**
574      * Creates an unnamed savepoint in the current transaction and
575      * returns the new <code>Savepoint</code> object that represents it.
576      *
577      * <p>QED: <code>Savepoint</code>s not supported.</p>
578      *
579      * @return the new <code>Savepoint</code> object
580      * @exception SQLException if a database access error occurs
581      * or this <code>Connection</code> object is currently in
582      * auto-commit mode
583      * @see Savepoint
584      * @since 1.4
585      */

586     public Savepoint JavaDoc setSavepoint() throws SQLException JavaDoc {
587         throw new SQLException JavaDoc("Not implemented");
588     }
589
590     /**
591      * Creates a savepoint with the given name in the current transaction
592      * and returns the new <code>Savepoint</code> object that represents it.
593      *
594      * <p>QED: <code>Savepoint</code>s not supported.</p>
595      *
596      * @param name a <code>String</code> containing the name of the savepoint
597      * @return the new <code>Savepoint</code> object
598      * @exception SQLException if a database access error occurs
599      * or this <code>Connection</code> object is currently in
600      * auto-commit mode
601      * @see Savepoint
602      * @since 1.4
603      */

604     public Savepoint JavaDoc setSavepoint(String JavaDoc name) throws SQLException JavaDoc {
605         throw new SQLException JavaDoc("Not implemented");
606     }
607
608     /**
609      * Undoes all changes made after the given <code>Savepoint</code> object
610      * was set.
611      * <P>
612      * This method should be used only when auto-commit has been disabled.
613      *
614      * <p>QED: <code>Savepoint</code>s not supported.</p>
615      *
616      * @param savepoint the <code>Savepoint</code> object to roll back to
617      * @exception SQLException if a database access error occurs,
618      * the <code>Savepoint</code> object is no longer valid,
619      * or this <code>Connection</code> object is currently in
620      * auto-commit mode
621      * @see Savepoint
622      * @see #rollback
623      * @since 1.4
624      */

625     public void rollback(Savepoint JavaDoc savepoint) throws SQLException JavaDoc {
626         throw new SQLException JavaDoc("Not implemented");
627     }
628
629     /**
630      * Removes the given <code>Savepoint</code> object from the current
631      * transaction. Any reference to the savepoint after it have been removed
632      * will cause an <code>SQLException</code> to be thrown.
633      *
634      * <p>QED: <code>Savepoint</code>s not supported.</p>
635      *
636      * @param savepoint the <code>Savepoint</code> object to be removed
637      * @exception SQLException if a database access error occurs or
638      * the given <code>Savepoint</code> object is not a valid
639      * savepoint in the current transaction
640      * @since 1.4
641      */

642     public void releaseSavepoint(Savepoint JavaDoc savepoint) throws SQLException JavaDoc {
643         throw new SQLException JavaDoc("Not implemented");
644     }
645
646     /**
647      * Creates a <code>Statement</code> object that will generate
648      * <code>ResultSet</code> objects with the given type, concurrency,
649      * and holdability.
650      * This method is the same as the <code>createStatement</code> method
651      * above, but it allows the default result set
652      * type, concurrency, and holdability to be overridden.
653      *
654      * @param resultSetType one of the following <code>ResultSet</code>
655      * constants:
656      * <code>ResultSet.TYPE_FORWARD_ONLY</code>,
657      * <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
658      * <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
659      * @param resultSetConcurrency one of the following <code>ResultSet</code>
660      * constants:
661      * <code>ResultSet.CONCUR_READ_ONLY</code> or
662      * <code>ResultSet.CONCUR_UPDATABLE</code>
663      * @param resultSetHoldability one of the following <code>ResultSet</code>
664      * constants:
665      * <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
666      * <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
667      * @return a new <code>Statement</code> object that will generate
668      * <code>ResultSet</code> objects with the given type,
669      * concurrency, and holdability
670      * @exception SQLException if a database access error occurs
671      * or the given parameters are not <code>ResultSet</code>
672      * constants indicating type, concurrency, and holdability
673      * @see ResultSet
674      * @since 1.4
675      */

676     public java.sql.Statement JavaDoc createStatement(int resultSetType,
677                                      int resultSetConcurrency,
678                                      int resultSetHoldability)
679         throws SQLException JavaDoc
680     {
681         setHoldability(resultSetHoldability);
682         return createStatement(resultSetType, resultSetConcurrency);
683     }
684
685     /**
686      * Creates a <code>PreparedStatement</code> object that will generate
687      * <code>ResultSet</code> objects with the given type, concurrency,
688      * and holdability.
689      * <P>
690      * This method is the same as the <code>prepareStatement</code> method
691      * above, but it allows the default result set
692      * type, concurrency, and holdability to be overridden.
693      *
694      * @param sql a <code>String</code> object that is the SQL statement to
695      * be sent to the database; may contain one or more ? IN
696      * parameters
697      * @param resultSetType one of the following <code>ResultSet</code>
698      * constants:
699      * <code>ResultSet.TYPE_FORWARD_ONLY</code>,
700      * <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
701      * <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
702      * @param resultSetConcurrency one of the following <code>ResultSet</code>
703      * constants:
704      * <code>ResultSet.CONCUR_READ_ONLY</code> or
705      * <code>ResultSet.CONCUR_UPDATABLE</code>
706      * @param resultSetHoldability one of the following <code>ResultSet</code>
707      * constants:
708      * <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
709      * <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
710      * @return a new <code>PreparedStatement</code> object, containing the
711      * pre-compiled SQL statement, that will generate
712      * <code>ResultSet</code> objects with the given type,
713      * concurrency, and holdability
714      * @exception SQLException if a database access error occurs
715      * or the given parameters are not <code>ResultSet</code>
716      * constants indicating type, concurrency, and holdability
717      * @see ResultSet
718      * @since 1.4
719      */

720     public
721     java.sql.PreparedStatement JavaDoc prepareStatement(String JavaDoc sql, int resultSetType,
722                        int resultSetConcurrency,
723                                        int resultSetHoldability)
724     throws SQLException JavaDoc {
725         setHoldability(resultSetHoldability);
726         return prepareStatement(sql, resultSetType, resultSetConcurrency);
727     }
728
729     /**
730      * Creates a <code>CallableStatement</code> object that will generate
731      * <code>ResultSet</code> objects with the given type and concurrency.
732      * This method is the same as the <code>prepareCall</code> method
733      * above, but it allows the default result set
734      * type, result set concurrency type and holdability to be overridden.
735      *
736      * @param sql a <code>String</code> object that is the SQL statement to
737      * be sent to the database; may contain on or more ? parameters
738      * @param resultSetType one of the following <code>ResultSet</code>
739      * constants:
740      * <code>ResultSet.TYPE_FORWARD_ONLY</code>,
741      * <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
742      * <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
743      * @param resultSetConcurrency one of the following <code>ResultSet</code>
744      * constants:
745      * <code>ResultSet.CONCUR_READ_ONLY</code> or
746      * <code>ResultSet.CONCUR_UPDATABLE</code>
747      * @param resultSetHoldability one of the following <code>ResultSet</code>
748      * constants:
749      * <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
750      * <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
751      * @return a new <code>CallableStatement</code> object, containing the
752      * pre-compiled SQL statement, that will generate
753      * <code>ResultSet</code> objects with the given type,
754      * concurrency, and holdability
755      * @exception SQLException if a database access error occurs
756      * or the given parameters are not <code>ResultSet</code>
757      * constants indicating type, concurrency, and holdability
758      * @see ResultSet
759      * @since 1.4
760      */

761     public
762     CallableStatement JavaDoc prepareCall(String JavaDoc sql, int resultSetType,
763                   int resultSetConcurrency,
764                   int resultSetHoldability)
765         throws SQLException JavaDoc
766     {
767         setHoldability(resultSetHoldability);
768         return prepareCall(sql, resultSetType, resultSetConcurrency);
769     }
770
771     /**
772      * Creates a default <code>PreparedStatement</code> object that has
773      * the capability to retrieve auto-generated keys. The given constant
774      * tells the driver whether it should make auto-generated keys
775      * available for retrieval. This parameter is ignored if the SQL
776      * statement is not an <code>INSERT</code> statement.
777      * <P>
778      * <B>Note:</B> This method is optimized for handling
779      * parametric SQL statements that benefit from precompilation. If
780      * the driver supports precompilation,
781      * the method <code>prepareStatement</code> will send
782      * the statement to the database for precompilation. Some drivers
783      * may not support precompilation. In this case, the statement may
784      * not be sent to the database until the <code>PreparedStatement</code>
785      * object is executed. This has no direct effect on users; however, it does
786      * affect which methods throw certain SQLExceptions.
787      * <P>
788      * Result sets created using the returned <code>PreparedStatement</code>
789      * object will by default be type <code>TYPE_FORWARD_ONLY</code>
790      * and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
791      *
792      * @param sql an SQL statement that may contain one or more '?' IN
793      * parameter placeholders
794      * @param autoGeneratedKeys a flag indicating whether auto-generated keys
795      * should be returned; one of the following <code>Statement</code>
796      * constants:
797      * @param autoGeneratedKeys a flag indicating that auto-generated keys
798      * should be returned, one of
799      * <code>Statement.RETURN_GENERATED_KEYS</code> or
800      * <code>Statement.NO_GENERATED_KEYS</code>.
801      * @return a new <code>PreparedStatement</code> object, containing the
802      * pre-compiled SQL statement, that will have the capability of
803      * returning auto-generated keys
804      * @exception SQLException if a database access error occurs
805      * or the given parameter is not a <code>Statement</code>
806      * constant indicating whether auto-generated keys should be
807      * returned
808      * @since 1.4
809      */

810     public
811     java.sql.PreparedStatement JavaDoc prepareStatement(String JavaDoc sql,
812                                                 int autoGeneratedKeys)
813     throws SQLException JavaDoc
814     {
815         if (autoGeneratedKeys == Statement.RETURN_GENERATED_KEYS) {
816             throw new SQLException JavaDoc("RETURN_GENERATED_KEYS not implemented");
817         }
818         return prepareStatement(sql);
819     }
820
821     /**
822      * Creates a default <code>PreparedStatement</code> object capable
823      * of returning the auto-generated keys designated by the given array.
824      * This array contains the indexes of the columns in the target
825      * table that contain the auto-generated keys that should be made
826      * available. This array is ignored if the SQL
827      * statement is not an <code>INSERT</code> statement.
828      * <P>
829      * An SQL statement with or without IN parameters can be
830      * pre-compiled and stored in a <code>PreparedStatement</code> object. This
831      * object can then be used to efficiently execute this statement
832      * multiple times.
833      * <P>
834      * <B>Note:</B> This method is optimized for handling
835      * parametric SQL statements that benefit from precompilation. If
836      * the driver supports precompilation,
837      * the method <code>prepareStatement</code> will send
838      * the statement to the database for precompilation. Some drivers
839      * may not support precompilation. In this case, the statement may
840      * not be sent to the database until the <code>PreparedStatement</code>
841      * object is executed. This has no direct effect on users; however, it does
842      * affect which methods throw certain SQLExceptions.
843      * <P>
844      * Result sets created using the returned <code>PreparedStatement</code>
845      * object will by default be type <code>TYPE_FORWARD_ONLY</code>
846      * and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
847      *
848      * @param sql an SQL statement that may contain one or more '?' IN
849      * parameter placeholders
850      * @param columnIndexes an array of column indexes indicating the columns
851      * that should be returned from the inserted row or rows
852      * @return a new <code>PreparedStatement</code> object, containing the
853      * pre-compiled statement, that is capable of returning the
854      * auto-generated keys designated by the given array of column
855      * indexes
856      * @exception SQLException if a database access error occurs
857      *
858      * @since 1.4
859      */

860     public
861     java.sql.PreparedStatement JavaDoc prepareStatement(String JavaDoc sql,
862                                                 int columnIndexes[])
863     throws SQLException JavaDoc
864     {
865         throw new SQLException JavaDoc("RETURN_GENERATED_KEYS not implemented");
866     }
867
868     /**
869      * Creates a default <code>PreparedStatement</code> object capable
870      * of returning the auto-generated keys designated by the given array.
871      * This array contains the names of the columns in the target
872      * table that contain the auto-generated keys that should be returned.
873      * This array is ignored if the SQL
874      * statement is not an <code>INSERT</code> statement.
875      * <P>
876      * An SQL statement with or without IN parameters can be
877      * pre-compiled and stored in a <code>PreparedStatement</code> object. This
878      * object can then be used to efficiently execute this statement
879      * multiple times.
880      * <P>
881      * <B>Note:</B> This method is optimized for handling
882      * parametric SQL statements that benefit from precompilation. If
883      * the driver supports precompilation,
884      * the method <code>prepareStatement</code> will send
885      * the statement to the database for precompilation. Some drivers
886      * may not support precompilation. In this case, the statement may
887      * not be sent to the database until the <code>PreparedStatement</code>
888      * object is executed. This has no direct effect on users; however, it does
889      * affect which methods throw certain SQLExceptions.
890      * <P>
891      * Result sets created using the returned <code>PreparedStatement</code>
892      * object will by default be type <code>TYPE_FORWARD_ONLY</code>
893      * and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
894      *
895      * @param sql an SQL statement that may contain one or more '?' IN
896      * parameter placeholders
897      * @param columnNames an array of column names indicating the columns
898      * that should be returned from the inserted row or rows
899      * @return a new <code>PreparedStatement</code> object, containing the
900      * pre-compiled statement, that is capable of returning the
901      * auto-generated keys designated by the given array of column
902      * names
903      * @exception SQLException if a database access error occurs
904      *
905      * @since 1.4
906      */

907     public
908     java.sql.PreparedStatement JavaDoc prepareStatement(String JavaDoc sql,
909                                                 String JavaDoc columnNames[])
910     throws SQLException JavaDoc
911     {
912         throw new SQLException JavaDoc("RETURN_GENERATED_KEYS not implemented");
913     }
914     //#endif
915
}
916
Popular Tags