• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This code is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 2 only, as
8  * published by the Free Software Foundation.  Oracle designates this
9  * particular file as subject to the "Classpath" exception as provided
10  * by Oracle in the LICENSE file that accompanied this code.
11  *
12  * This code is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15  * version 2 for more details (a copy is included in the LICENSE file that
16  * accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License version
19  * 2 along with this work; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21  *
22  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23  * or visit www.oracle.com if you need additional information or have any
24  * questions.
25  */
26 
27 package java.sql;
28 
29 /**
30  * <P>The object used for executing a static SQL statement
31  * and returning the results it produces.
32  * <P>
33  * By default, only one <code>ResultSet</code> object per <code>Statement</code>
34  * object can be open at the same time. Therefore, if the reading of one
35  * <code>ResultSet</code> object is interleaved
36  * with the reading of another, each must have been generated by
37  * different <code>Statement</code> objects. All execution methods in the
38  * <code>Statement</code> interface implicitly close a statment's current
39  * <code>ResultSet</code> object if an open one exists.
40  *
41  * @see Connection#createStatement
42  * @see ResultSet
43  */
44 public interface Statement extends Wrapper, AutoCloseable {
45 
46     /**
47      * Executes the given SQL statement, which returns a single
48      * <code>ResultSet</code> object.
49      *<p>
50      * <strong>Note:</strong>This method cannot be called on a
51      * <code>PreparedStatement</code> or <code>CallableStatement</code>.
52      * @param sql an SQL statement to be sent to the database, typically a
53      *        static SQL <code>SELECT</code> statement
54      * @return a <code>ResultSet</code> object that contains the data produced
55      *         by the given query; never <code>null</code>
56      * @exception SQLException if a database access error occurs,
57      * this method is called on a closed <code>Statement</code>, the given
58      *            SQL statement produces anything other than a single
59      *            <code>ResultSet</code> object, the method is called on a
60      * <code>PreparedStatement</code> or <code>CallableStatement</code>
61      * @throws SQLTimeoutException when the driver has determined that the
62      * timeout value that was specified by the {@code setQueryTimeout}
63      * method has been exceeded and has at least attempted to cancel
64      * the currently running {@code Statement}
65      */
executeQuery(String sql)66     ResultSet executeQuery(String sql) throws SQLException;
67 
68     /**
69      * Executes the given SQL statement, which may be an <code>INSERT</code>,
70      * <code>UPDATE</code>, or <code>DELETE</code> statement or an
71      * SQL statement that returns nothing, such as an SQL DDL statement.
72      *<p>
73      * <strong>Note:</strong>This method cannot be called on a
74      * <code>PreparedStatement</code> or <code>CallableStatement</code>.
75      * @param sql an SQL Data Manipulation Language (DML) statement, such as <code>INSERT</code>, <code>UPDATE</code> or
76      * <code>DELETE</code>; or an SQL statement that returns nothing,
77      * such as a DDL statement.
78      *
79      * @return either (1) the row count for SQL Data Manipulation Language (DML) statements
80      *         or (2) 0 for SQL statements that return nothing
81      *
82      * @exception SQLException if a database access error occurs,
83      * this method is called on a closed <code>Statement</code>, the given
84      * SQL statement produces a <code>ResultSet</code> object, the method is called on a
85      * <code>PreparedStatement</code> or <code>CallableStatement</code>
86      * @throws SQLTimeoutException when the driver has determined that the
87      * timeout value that was specified by the {@code setQueryTimeout}
88      * method has been exceeded and has at least attempted to cancel
89      * the currently running {@code Statement}
90      */
executeUpdate(String sql)91     int executeUpdate(String sql) throws SQLException;
92 
93     /**
94      * Releases this <code>Statement</code> object's database
95      * and JDBC resources immediately instead of waiting for
96      * this to happen when it is automatically closed.
97      * It is generally good practice to release resources as soon as
98      * you are finished with them to avoid tying up database
99      * resources.
100      * <P>
101      * Calling the method <code>close</code> on a <code>Statement</code>
102      * object that is already closed has no effect.
103      * <P>
104      * <B>Note:</B>When a <code>Statement</code> object is
105      * closed, its current <code>ResultSet</code> object, if one exists, is
106      * also closed.
107      *
108      * @exception SQLException if a database access error occurs
109      */
close()110     void close() throws SQLException;
111 
112     //----------------------------------------------------------------------
113 
114     /**
115      * Retrieves the maximum number of bytes that can be
116      * returned for character and binary column values in a <code>ResultSet</code>
117      * object produced by this <code>Statement</code> object.
118      * This limit applies only to  <code>BINARY</code>, <code>VARBINARY</code>,
119      * <code>LONGVARBINARY</code>, <code>CHAR</code>, <code>VARCHAR</code>,
120      * <code>NCHAR</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code>
121      * and <code>LONGVARCHAR</code> columns.  If the limit is exceeded, the
122      * excess data is silently discarded.
123      *
124      * @return the current column size limit for columns storing character and
125      *         binary values; zero means there is no limit
126      * @exception SQLException if a database access error occurs or
127      * this method is called on a closed <code>Statement</code>
128      * @see #setMaxFieldSize
129      */
getMaxFieldSize()130     int getMaxFieldSize() throws SQLException;
131 
132     /**
133      * Sets the limit for the maximum number of bytes that can be returned for
134      * character and binary column values in a <code>ResultSet</code>
135      * object produced by this <code>Statement</code> object.
136      *
137      * This limit applies
138      * only to <code>BINARY</code>, <code>VARBINARY</code>,
139      * <code>LONGVARBINARY</code>, <code>CHAR</code>, <code>VARCHAR</code>,
140      * <code>NCHAR</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code> and
141      * <code>LONGVARCHAR</code> fields.  If the limit is exceeded, the excess data
142      * is silently discarded. For maximum portability, use values
143      * greater than 256.
144      *
145      * @param max the new column size limit in bytes; zero means there is no limit
146      * @exception SQLException if a database access error occurs,
147      * this method is called on a closed <code>Statement</code>
148      *            or the condition max >= 0 is not satisfied
149      * @see #getMaxFieldSize
150      */
setMaxFieldSize(int max)151     void setMaxFieldSize(int max) throws SQLException;
152 
153     /**
154      * Retrieves the maximum number of rows that a
155      * <code>ResultSet</code> object produced by this
156      * <code>Statement</code> object can contain.  If this limit is exceeded,
157      * the excess rows are silently dropped.
158      *
159      * @return the current maximum number of rows for a <code>ResultSet</code>
160      *         object produced by this <code>Statement</code> object;
161      *         zero means there is no limit
162      * @exception SQLException if a database access error occurs or
163      * this method is called on a closed <code>Statement</code>
164      * @see #setMaxRows
165      */
getMaxRows()166     int getMaxRows() throws SQLException;
167 
168     /**
169      * Sets the limit for the maximum number of rows that any
170      * <code>ResultSet</code> object  generated by this <code>Statement</code>
171      * object can contain to the given number.
172      * If the limit is exceeded, the excess
173      * rows are silently dropped.
174      *
175      * @param max the new max rows limit; zero means there is no limit
176      * @exception SQLException if a database access error occurs,
177      * this method is called on a closed <code>Statement</code>
178      *            or the condition max >= 0 is not satisfied
179      * @see #getMaxRows
180      */
setMaxRows(int max)181     void setMaxRows(int max) throws SQLException;
182 
183     /**
184      * Sets escape processing on or off.
185      * If escape scanning is on (the default), the driver will do
186      * escape substitution before sending the SQL statement to the database.
187      *
188      * Note: Since prepared statements have usually been parsed prior
189      * to making this call, disabling escape processing for
190      * <code>PreparedStatements</code> objects will have no effect.
191      *
192      * @param enable <code>true</code> to enable escape processing;
193      *       <code>false</code> to disable it
194      * @exception SQLException if a database access error occurs or
195      * this method is called on a closed <code>Statement</code>
196      */
setEscapeProcessing(boolean enable)197     void setEscapeProcessing(boolean enable) throws SQLException;
198 
199     /**
200      * Retrieves the number of seconds the driver will
201      * wait for a <code>Statement</code> object to execute.
202      * If the limit is exceeded, a
203      * <code>SQLException</code> is thrown.
204      *
205      * @return the current query timeout limit in seconds; zero means there is
206      *         no limit
207      * @exception SQLException if a database access error occurs or
208      * this method is called on a closed <code>Statement</code>
209      * @see #setQueryTimeout
210      */
getQueryTimeout()211     int getQueryTimeout() throws SQLException;
212 
213     /**
214      * Sets the number of seconds the driver will wait for a
215      * <code>Statement</code> object to execute to the given number of seconds.
216      *By default there is no limit on the amount of time allowed for a running
217      * statement to complete. If the limit is exceeded, an
218      * <code>SQLTimeoutException</code> is thrown.
219      * A JDBC driver must apply this limit to the <code>execute</code>,
220      * <code>executeQuery</code> and <code>executeUpdate</code> methods.
221      * <p>
222      * <strong>Note:</strong> JDBC driver implementations may also apply this
223      * limit to {@code ResultSet} methods
224      * (consult your driver vendor documentation for details).
225      * <p>
226      * <strong>Note:</strong> In the case of {@code Statement} batching, it is
227      * implementation defined as to whether the time-out is applied to
228      * individual SQL commands added via the {@code addBatch} method or to
229      * the entire batch of SQL commands invoked by the {@code executeBatch}
230      * method (consult your driver vendor documentation for details).
231      *
232      * @param seconds the new query timeout limit in seconds; zero means
233      *        there is no limit
234      * @exception SQLException if a database access error occurs,
235      * this method is called on a closed <code>Statement</code>
236      *            or the condition seconds >= 0 is not satisfied
237      * @see #getQueryTimeout
238      */
setQueryTimeout(int seconds)239     void setQueryTimeout(int seconds) throws SQLException;
240 
241     /**
242      * Cancels this <code>Statement</code> object if both the DBMS and
243      * driver support aborting an SQL statement.
244      * This method can be used by one thread to cancel a statement that
245      * is being executed by another thread.
246      *
247      * @exception SQLException if a database access error occurs or
248      * this method is called on a closed <code>Statement</code>
249      * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
250      * this method
251      */
cancel()252     void cancel() throws SQLException;
253 
254     /**
255      * Retrieves the first warning reported by calls on this <code>Statement</code> object.
256      * Subsequent <code>Statement</code> object warnings will be chained to this
257      * <code>SQLWarning</code> object.
258      *
259      * <p>The warning chain is automatically cleared each time
260      * a statement is (re)executed. This method may not be called on a closed
261      * <code>Statement</code> object; doing so will cause an <code>SQLException</code>
262      * to be thrown.
263      *
264      * <P><B>Note:</B> If you are processing a <code>ResultSet</code> object, any
265      * warnings associated with reads on that <code>ResultSet</code> object
266      * will be chained on it rather than on the <code>Statement</code>
267      * object that produced it.
268      *
269      * @return the first <code>SQLWarning</code> object or <code>null</code>
270      *         if there are no warnings
271      * @exception SQLException if a database access error occurs or
272      * this method is called on a closed <code>Statement</code>
273      */
getWarnings()274     SQLWarning getWarnings() throws SQLException;
275 
276     /**
277      * Clears all the warnings reported on this <code>Statement</code>
278      * object. After a call to this method,
279      * the method <code>getWarnings</code> will return
280      * <code>null</code> until a new warning is reported for this
281      * <code>Statement</code> object.
282      *
283      * @exception SQLException if a database access error occurs or
284      * this method is called on a closed <code>Statement</code>
285      */
clearWarnings()286     void clearWarnings() throws SQLException;
287 
288     /**
289      * Sets the SQL cursor name to the given <code>String</code>, which
290      * will be used by subsequent <code>Statement</code> object
291      * <code>execute</code> methods. This name can then be
292      * used in SQL positioned update or delete statements to identify the
293      * current row in the <code>ResultSet</code> object generated by this
294      * statement.  If the database does not support positioned update/delete,
295      * this method is a noop.  To insure that a cursor has the proper isolation
296      * level to support updates, the cursor's <code>SELECT</code> statement
297      * should have the form <code>SELECT FOR UPDATE</code>.  If
298      * <code>FOR UPDATE</code> is not present, positioned updates may fail.
299      *
300      * <P><B>Note:</B> By definition, the execution of positioned updates and
301      * deletes must be done by a different <code>Statement</code> object than
302      * the one that generated the <code>ResultSet</code> object being used for
303      * positioning. Also, cursor names must be unique within a connection.
304      *
305      * @param name the new cursor name, which must be unique within
306      *             a connection
307      * @exception SQLException if a database access error occurs or
308      * this method is called on a closed <code>Statement</code>
309      * @throws SQLFeatureNotSupportedException  if the JDBC driver does not support this method
310      */
setCursorName(String name)311     void setCursorName(String name) throws SQLException;
312 
313     //----------------------- Multiple Results --------------------------
314 
315     /**
316      * Executes the given SQL statement, which may return multiple results.
317      * In some (uncommon) situations, a single SQL statement may return
318      * multiple result sets and/or update counts.  Normally you can ignore
319      * this unless you are (1) executing a stored procedure that you know may
320      * return multiple results or (2) you are dynamically executing an
321      * unknown SQL string.
322      * <P>
323      * The <code>execute</code> method executes an SQL statement and indicates the
324      * form of the first result.  You must then use the methods
325      * <code>getResultSet</code> or <code>getUpdateCount</code>
326      * to retrieve the result, and <code>getMoreResults</code> to
327      * move to any subsequent result(s).
328      * <p>
329      *<strong>Note:</strong>This method cannot be called on a
330      * <code>PreparedStatement</code> or <code>CallableStatement</code>.
331      * @param sql any SQL statement
332      * @return <code>true</code> if the first result is a <code>ResultSet</code>
333      *         object; <code>false</code> if it is an update count or there are
334      *         no results
335      * @exception SQLException if a database access error occurs,
336      * this method is called on a closed <code>Statement</code>,
337      * the method is called on a
338      * <code>PreparedStatement</code> or <code>CallableStatement</code>
339      * @throws SQLTimeoutException when the driver has determined that the
340      * timeout value that was specified by the {@code setQueryTimeout}
341      * method has been exceeded and has at least attempted to cancel
342      * the currently running {@code Statement}
343      * @see #getResultSet
344      * @see #getUpdateCount
345      * @see #getMoreResults
346      */
execute(String sql)347     boolean execute(String sql) throws SQLException;
348 
349     /**
350      *  Retrieves the current result as a <code>ResultSet</code> object.
351      *  This method should be called only once per result.
352      *
353      * @return the current result as a <code>ResultSet</code> object or
354      * <code>null</code> if the result is an update count or there are no more results
355      * @exception SQLException if a database access error occurs or
356      * this method is called on a closed <code>Statement</code>
357      * @see #execute
358      */
getResultSet()359     ResultSet getResultSet() throws SQLException;
360 
361     /**
362      *  Retrieves the current result as an update count;
363      *  if the result is a <code>ResultSet</code> object or there are no more results, -1
364      *  is returned. This method should be called only once per result.
365      *
366      * @return the current result as an update count; -1 if the current result is a
367      * <code>ResultSet</code> object or there are no more results
368      * @exception SQLException if a database access error occurs or
369      * this method is called on a closed <code>Statement</code>
370      * @see #execute
371      */
getUpdateCount()372     int getUpdateCount() throws SQLException;
373 
374     /**
375      * Moves to this <code>Statement</code> object's next result, returns
376      * <code>true</code> if it is a <code>ResultSet</code> object, and
377      * implicitly closes any current <code>ResultSet</code>
378      * object(s) obtained with the method <code>getResultSet</code>.
379      *
380      * <P>There are no more results when the following is true:
381      * <PRE>
382      *     // stmt is a Statement object
383      *     ((stmt.getMoreResults() == false) && (stmt.getUpdateCount() == -1))
384      * </PRE>
385      *
386      * @return <code>true</code> if the next result is a <code>ResultSet</code>
387      *         object; <code>false</code> if it is an update count or there are
388      *         no more results
389      * @exception SQLException if a database access error occurs or
390      * this method is called on a closed <code>Statement</code>
391      * @see #execute
392      */
getMoreResults()393     boolean getMoreResults() throws SQLException;
394 
395 
396     //--------------------------JDBC 2.0-----------------------------
397 
398 
399     /**
400      * Gives the driver a hint as to the direction in which
401      * rows will be processed in <code>ResultSet</code>
402      * objects created using this <code>Statement</code> object.  The
403      * default value is <code>ResultSet.FETCH_FORWARD</code>.
404      * <P>
405      * Note that this method sets the default fetch direction for
406      * result sets generated by this <code>Statement</code> object.
407      * Each result set has its own methods for getting and setting
408      * its own fetch direction.
409      *
410      * @param direction the initial direction for processing rows
411      * @exception SQLException if a database access error occurs,
412      * this method is called on a closed <code>Statement</code>
413      * or the given direction
414      * is not one of <code>ResultSet.FETCH_FORWARD</code>,
415      * <code>ResultSet.FETCH_REVERSE</code>, or <code>ResultSet.FETCH_UNKNOWN</code>
416      * @since 1.2
417      * @see #getFetchDirection
418      */
setFetchDirection(int direction)419     void setFetchDirection(int direction) throws SQLException;
420 
421     /**
422      * Retrieves the direction for fetching rows from
423      * database tables that is the default for result sets
424      * generated from this <code>Statement</code> object.
425      * If this <code>Statement</code> object has not set
426      * a fetch direction by calling the method <code>setFetchDirection</code>,
427      * the return value is implementation-specific.
428      *
429      * @return the default fetch direction for result sets generated
430      *          from this <code>Statement</code> object
431      * @exception SQLException if a database access error occurs or
432      * this method is called on a closed <code>Statement</code>
433      * @since 1.2
434      * @see #setFetchDirection
435      */
getFetchDirection()436     int getFetchDirection() throws SQLException;
437 
438     /**
439      * Gives the JDBC driver a hint as to the number of rows that should
440      * be fetched from the database when more rows are needed for
441      * <code>ResultSet</code> objects genrated by this <code>Statement</code>.
442      * If the value specified is zero, then the hint is ignored.
443      * The default value is zero.
444      *
445      * @param rows the number of rows to fetch
446      * @exception SQLException if a database access error occurs,
447      * this method is called on a closed <code>Statement</code> or the
448      *        condition  <code>rows >= 0</code> is not satisfied.
449      * @since 1.2
450      * @see #getFetchSize
451      */
setFetchSize(int rows)452     void setFetchSize(int rows) throws SQLException;
453 
454     /**
455      * Retrieves the number of result set rows that is the default
456      * fetch size for <code>ResultSet</code> objects
457      * generated from this <code>Statement</code> object.
458      * If this <code>Statement</code> object has not set
459      * a fetch size by calling the method <code>setFetchSize</code>,
460      * the return value is implementation-specific.
461      *
462      * @return the default fetch size for result sets generated
463      *          from this <code>Statement</code> object
464      * @exception SQLException if a database access error occurs or
465      * this method is called on a closed <code>Statement</code>
466      * @since 1.2
467      * @see #setFetchSize
468      */
getFetchSize()469     int getFetchSize() throws SQLException;
470 
471     /**
472      * Retrieves the result set concurrency for <code>ResultSet</code> objects
473      * generated by this <code>Statement</code> object.
474      *
475      * @return either <code>ResultSet.CONCUR_READ_ONLY</code> or
476      * <code>ResultSet.CONCUR_UPDATABLE</code>
477      * @exception SQLException if a database access error occurs or
478      * this method is called on a closed <code>Statement</code>
479      * @since 1.2
480      */
getResultSetConcurrency()481     int getResultSetConcurrency() throws SQLException;
482 
483     /**
484      * Retrieves the result set type for <code>ResultSet</code> objects
485      * generated by this <code>Statement</code> object.
486      *
487      * @return one of <code>ResultSet.TYPE_FORWARD_ONLY</code>,
488      * <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
489      * <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
490      * @exception SQLException if a database access error occurs or
491      * this method is called on a closed <code>Statement</code>
492      * @since 1.2
493      */
getResultSetType()494     int getResultSetType()  throws SQLException;
495 
496     /**
497      * Adds the given SQL command to the current list of commmands for this
498      * <code>Statement</code> object. The commands in this list can be
499      * executed as a batch by calling the method <code>executeBatch</code>.
500      * <P>
501      *<strong>Note:</strong>This method cannot be called on a
502      * <code>PreparedStatement</code> or <code>CallableStatement</code>.
503      * @param sql typically this is a SQL <code>INSERT</code> or
504      * <code>UPDATE</code> statement
505      * @exception SQLException if a database access error occurs,
506      * this method is called on a closed <code>Statement</code>, the
507      * driver does not support batch updates, the method is called on a
508      * <code>PreparedStatement</code> or <code>CallableStatement</code>
509      * @see #executeBatch
510      * @see DatabaseMetaData#supportsBatchUpdates
511      * @since 1.2
512      */
addBatch( String sql )513     void addBatch( String sql ) throws SQLException;
514 
515     /**
516      * Empties this <code>Statement</code> object's current list of
517      * SQL commands.
518      * <P>
519      * @exception SQLException if a database access error occurs,
520      *  this method is called on a closed <code>Statement</code> or the
521      * driver does not support batch updates
522      * @see #addBatch
523      * @see DatabaseMetaData#supportsBatchUpdates
524      * @since 1.2
525      */
clearBatch()526     void clearBatch() throws SQLException;
527 
528     /**
529      * Submits a batch of commands to the database for execution and
530      * if all commands execute successfully, returns an array of update counts.
531      * The <code>int</code> elements of the array that is returned are ordered
532      * to correspond to the commands in the batch, which are ordered
533      * according to the order in which they were added to the batch.
534      * The elements in the array returned by the method <code>executeBatch</code>
535      * may be one of the following:
536      * <OL>
537      * <LI>A number greater than or equal to zero -- indicates that the
538      * command was processed successfully and is an update count giving the
539      * number of rows in the database that were affected by the command's
540      * execution
541      * <LI>A value of <code>SUCCESS_NO_INFO</code> -- indicates that the command was
542      * processed successfully but that the number of rows affected is
543      * unknown
544      * <P>
545      * If one of the commands in a batch update fails to execute properly,
546      * this method throws a <code>BatchUpdateException</code>, and a JDBC
547      * driver may or may not continue to process the remaining commands in
548      * the batch.  However, the driver's behavior must be consistent with a
549      * particular DBMS, either always continuing to process commands or never
550      * continuing to process commands.  If the driver continues processing
551      * after a failure, the array returned by the method
552      * <code>BatchUpdateException.getUpdateCounts</code>
553      * will contain as many elements as there are commands in the batch, and
554      * at least one of the elements will be the following:
555      * <P>
556      * <LI>A value of <code>EXECUTE_FAILED</code> -- indicates that the command failed
557      * to execute successfully and occurs only if a driver continues to
558      * process commands after a command fails
559      * </OL>
560      * <P>
561      * The possible implementations and return values have been modified in
562      * the Java 2 SDK, Standard Edition, version 1.3 to
563      * accommodate the option of continuing to proccess commands in a batch
564      * update after a <code>BatchUpdateException</code> obejct has been thrown.
565      *
566      * @return an array of update counts containing one element for each
567      * command in the batch.  The elements of the array are ordered according
568      * to the order in which commands were added to the batch.
569      * @exception SQLException if a database access error occurs,
570      * this method is called on a closed <code>Statement</code> or the
571      * driver does not support batch statements. Throws {@link BatchUpdateException}
572      * (a subclass of <code>SQLException</code>) if one of the commands sent to the
573      * database fails to execute properly or attempts to return a result set.
574      * @throws SQLTimeoutException when the driver has determined that the
575      * timeout value that was specified by the {@code setQueryTimeout}
576      * method has been exceeded and has at least attempted to cancel
577      * the currently running {@code Statement}
578      *
579      * @see #addBatch
580      * @see DatabaseMetaData#supportsBatchUpdates
581      * @since 1.2
582      */
executeBatch()583     int[] executeBatch() throws SQLException;
584 
585     /**
586      * Retrieves the <code>Connection</code> object
587      * that produced this <code>Statement</code> object.
588      * @return the connection that produced this statement
589      * @exception SQLException if a database access error occurs or
590      * this method is called on a closed <code>Statement</code>
591      * @since 1.2
592      */
getConnection()593     Connection getConnection()  throws SQLException;
594 
595   //--------------------------JDBC 3.0-----------------------------
596 
597     /**
598      * The constant indicating that the current <code>ResultSet</code> object
599      * should be closed when calling <code>getMoreResults</code>.
600      *
601      * @since 1.4
602      */
603     int CLOSE_CURRENT_RESULT = 1;
604 
605     /**
606      * The constant indicating that the current <code>ResultSet</code> object
607      * should not be closed when calling <code>getMoreResults</code>.
608      *
609      * @since 1.4
610      */
611     int KEEP_CURRENT_RESULT = 2;
612 
613     /**
614      * The constant indicating that all <code>ResultSet</code> objects that
615      * have previously been kept open should be closed when calling
616      * <code>getMoreResults</code>.
617      *
618      * @since 1.4
619      */
620     int CLOSE_ALL_RESULTS = 3;
621 
622     /**
623      * The constant indicating that a batch statement executed successfully
624      * but that no count of the number of rows it affected is available.
625      *
626      * @since 1.4
627      */
628     int SUCCESS_NO_INFO = -2;
629 
630     /**
631      * The constant indicating that an error occured while executing a
632      * batch statement.
633      *
634      * @since 1.4
635      */
636     int EXECUTE_FAILED = -3;
637 
638     /**
639      * The constant indicating that generated keys should be made
640      * available for retrieval.
641      *
642      * @since 1.4
643      */
644     int RETURN_GENERATED_KEYS = 1;
645 
646     /**
647      * The constant indicating that generated keys should not be made
648      * available for retrieval.
649      *
650      * @since 1.4
651      */
652     int NO_GENERATED_KEYS = 2;
653 
654     /**
655      * Moves to this <code>Statement</code> object's next result, deals with
656      * any current <code>ResultSet</code> object(s) according  to the instructions
657      * specified by the given flag, and returns
658      * <code>true</code> if the next result is a <code>ResultSet</code> object.
659      *
660      * <P>There are no more results when the following is true:
661      * <PRE>
662      *     // stmt is a Statement object
663      *     ((stmt.getMoreResults(current) == false) && (stmt.getUpdateCount() == -1))
664      * </PRE>
665      *
666      * @param current one of the following <code>Statement</code>
667      *        constants indicating what should happen to current
668      *        <code>ResultSet</code> objects obtained using the method
669      *        <code>getResultSet</code>:
670      *        <code>Statement.CLOSE_CURRENT_RESULT</code>,
671      *        <code>Statement.KEEP_CURRENT_RESULT</code>, or
672      *        <code>Statement.CLOSE_ALL_RESULTS</code>
673      * @return <code>true</code> if the next result is a <code>ResultSet</code>
674      *         object; <code>false</code> if it is an update count or there are no
675      *         more results
676      * @exception SQLException if a database access error occurs,
677      * this method is called on a closed <code>Statement</code> or the argument
678          *         supplied is not one of the following:
679      *        <code>Statement.CLOSE_CURRENT_RESULT</code>,
680      *        <code>Statement.KEEP_CURRENT_RESULT</code> or
681      *        <code>Statement.CLOSE_ALL_RESULTS</code>
682      *@exception SQLFeatureNotSupportedException if
683      * <code>DatabaseMetaData.supportsMultipleOpenResults</code> returns
684      * <code>false</code> and either
685      *        <code>Statement.KEEP_CURRENT_RESULT</code> or
686      *        <code>Statement.CLOSE_ALL_RESULTS</code> are supplied as
687      * the argument.
688      * @since 1.4
689      * @see #execute
690      */
getMoreResults(int current)691     boolean getMoreResults(int current) throws SQLException;
692 
693     /**
694      * Retrieves any auto-generated keys created as a result of executing this
695      * <code>Statement</code> object. If this <code>Statement</code> object did
696      * not generate any keys, an empty <code>ResultSet</code>
697      * object is returned.
698      *
699      *<p><B>Note:</B>If the columns which represent the auto-generated keys were not specified,
700      * the JDBC driver implementation will determine the columns which best represent the auto-generated keys.
701      *
702      * @return a <code>ResultSet</code> object containing the auto-generated key(s)
703      *         generated by the execution of this <code>Statement</code> object
704      * @exception SQLException if a database access error occurs or
705      * this method is called on a closed <code>Statement</code>
706      * @throws SQLFeatureNotSupportedException  if the JDBC driver does not support this method
707      * @since 1.4
708      */
getGeneratedKeys()709     ResultSet getGeneratedKeys() throws SQLException;
710 
711     /**
712      * Executes the given SQL statement and signals the driver with the
713      * given flag about whether the
714      * auto-generated keys produced by this <code>Statement</code> object
715      * should be made available for retrieval.  The driver will ignore the
716      * flag if the SQL statement
717      * is not an <code>INSERT</code> statement, or an SQL statement able to return
718      * auto-generated keys (the list of such statements is vendor-specific).
719      *<p>
720      * <strong>Note:</strong>This method cannot be called on a
721      * <code>PreparedStatement</code> or <code>CallableStatement</code>.
722      * @param sql an SQL Data Manipulation Language (DML) statement, such as <code>INSERT</code>, <code>UPDATE</code> or
723      * <code>DELETE</code>; or an SQL statement that returns nothing,
724      * such as a DDL statement.
725      *
726      * @param autoGeneratedKeys a flag indicating whether auto-generated keys
727      *        should be made available for retrieval;
728      *         one of the following constants:
729      *         <code>Statement.RETURN_GENERATED_KEYS</code>
730      *         <code>Statement.NO_GENERATED_KEYS</code>
731      * @return either (1) the row count for SQL Data Manipulation Language (DML) statements
732      *         or (2) 0 for SQL statements that return nothing
733      *
734      * @exception SQLException if a database access error occurs,
735      *  this method is called on a closed <code>Statement</code>, the given
736      *            SQL statement returns a <code>ResultSet</code> object,
737      *            the given constant is not one of those allowed, the method is called on a
738      * <code>PreparedStatement</code> or <code>CallableStatement</code>
739      * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
740      * this method with a constant of Statement.RETURN_GENERATED_KEYS
741      * @throws SQLTimeoutException when the driver has determined that the
742      * timeout value that was specified by the {@code setQueryTimeout}
743      * method has been exceeded and has at least attempted to cancel
744      * the currently running {@code Statement}
745      * @since 1.4
746      */
executeUpdate(String sql, int autoGeneratedKeys)747     int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException;
748 
749     /**
750      * Executes the given SQL statement and signals the driver that the
751      * auto-generated keys indicated in the given array should be made available
752      * for retrieval.   This array contains the indexes of the columns in the
753      * target table that contain the auto-generated keys that should be made
754      * available. The driver will ignore the array if the SQL statement
755      * is not an <code>INSERT</code> statement, or an SQL statement able to return
756      * auto-generated keys (the list of such statements is vendor-specific).
757      *<p>
758      * <strong>Note:</strong>This method cannot be called on a
759      * <code>PreparedStatement</code> or <code>CallableStatement</code>.
760      * @param sql an SQL Data Manipulation Language (DML) statement, such as <code>INSERT</code>, <code>UPDATE</code> or
761      * <code>DELETE</code>; or an SQL statement that returns nothing,
762      * such as a DDL statement.
763      *
764      * @param columnIndexes an array of column indexes indicating the columns
765      *        that should be returned from the inserted row
766      * @return either (1) the row count for SQL Data Manipulation Language (DML) statements
767      *         or (2) 0 for SQL statements that return nothing
768      *
769      * @exception SQLException if a database access error occurs,
770      * this method is called on a closed <code>Statement</code>, the SQL
771      * statement returns a <code>ResultSet</code> object,the second argument
772      * supplied to this method is not an
773      * <code>int</code> array whose elements are valid column indexes, the method is called on a
774      * <code>PreparedStatement</code> or <code>CallableStatement</code>
775      * @throws SQLFeatureNotSupportedException  if the JDBC driver does not support this method
776      * @throws SQLTimeoutException when the driver has determined that the
777      * timeout value that was specified by the {@code setQueryTimeout}
778      * method has been exceeded and has at least attempted to cancel
779      * the currently running {@code Statement}
780      * @since 1.4
781      */
executeUpdate(String sql, int columnIndexes[])782     int executeUpdate(String sql, int columnIndexes[]) throws SQLException;
783 
784     /**
785      * Executes the given SQL statement and signals the driver that the
786      * auto-generated keys indicated in the given array should be made available
787      * for retrieval.   This array contains the names of the columns in the
788      * target table that contain the auto-generated keys that should be made
789      * available. The driver will ignore the array if the SQL statement
790      * is not an <code>INSERT</code> statement, or an SQL statement able to return
791      * auto-generated keys (the list of such statements is vendor-specific).
792      *<p>
793      * <strong>Note:</strong>This method cannot be called on a
794      * <code>PreparedStatement</code> or <code>CallableStatement</code>.
795      * @param sql an SQL Data Manipulation Language (DML) statement, such as <code>INSERT</code>, <code>UPDATE</code> or
796      * <code>DELETE</code>; or an SQL statement that returns nothing,
797      * such as a DDL statement.
798      * @param columnNames an array of the names of the columns that should be
799      *        returned from the inserted row
800      * @return either the row count for <code>INSERT</code>, <code>UPDATE</code>,
801      *         or <code>DELETE</code> statements, or 0 for SQL statements
802      *         that return nothing
803      * @exception SQLException if a database access error occurs,
804      *  this method is called on a closed <code>Statement</code>, the SQL
805      *            statement returns a <code>ResultSet</code> object, the
806      *            second argument supplied to this method is not a <code>String</code> array
807      *            whose elements are valid column names, the method is called on a
808      * <code>PreparedStatement</code> or <code>CallableStatement</code>
809      * @throws SQLFeatureNotSupportedException  if the JDBC driver does not support this method
810      * @throws SQLTimeoutException when the driver has determined that the
811      * timeout value that was specified by the {@code setQueryTimeout}
812      * method has been exceeded and has at least attempted to cancel
813      * the currently running {@code Statement}
814      * @since 1.4
815      */
executeUpdate(String sql, String columnNames[])816     int executeUpdate(String sql, String columnNames[]) throws SQLException;
817 
818     /**
819      * Executes the given SQL statement, which may return multiple results,
820      * and signals the driver that any
821      * auto-generated keys should be made available
822      * for retrieval.  The driver will ignore this signal if the SQL statement
823      * is not an <code>INSERT</code> statement, or an SQL statement able to return
824      * auto-generated keys (the list of such statements is vendor-specific).
825      * <P>
826      * In some (uncommon) situations, a single SQL statement may return
827      * multiple result sets and/or update counts.  Normally you can ignore
828      * this unless you are (1) executing a stored procedure that you know may
829      * return multiple results or (2) you are dynamically executing an
830      * unknown SQL string.
831      * <P>
832      * The <code>execute</code> method executes an SQL statement and indicates the
833      * form of the first result.  You must then use the methods
834      * <code>getResultSet</code> or <code>getUpdateCount</code>
835      * to retrieve the result, and <code>getMoreResults</code> to
836      * move to any subsequent result(s).
837      *<p>
838      *<strong>Note:</strong>This method cannot be called on a
839      * <code>PreparedStatement</code> or <code>CallableStatement</code>.
840      * @param sql any SQL statement
841      * @param autoGeneratedKeys a constant indicating whether auto-generated
842      *        keys should be made available for retrieval using the method
843      *        <code>getGeneratedKeys</code>; one of the following constants:
844      *        <code>Statement.RETURN_GENERATED_KEYS</code> or
845      *        <code>Statement.NO_GENERATED_KEYS</code>
846      * @return <code>true</code> if the first result is a <code>ResultSet</code>
847      *         object; <code>false</code> if it is an update count or there are
848      *         no results
849      * @exception SQLException if a database access error occurs,
850      * this method is called on a closed <code>Statement</code>, the second
851      *         parameter supplied to this method is not
852      *         <code>Statement.RETURN_GENERATED_KEYS</code> or
853      *         <code>Statement.NO_GENERATED_KEYS</code>,
854      * the method is called on a
855      * <code>PreparedStatement</code> or <code>CallableStatement</code>
856      * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
857      * this method with a constant of Statement.RETURN_GENERATED_KEYS
858      * @throws SQLTimeoutException when the driver has determined that the
859      * timeout value that was specified by the {@code setQueryTimeout}
860      * method has been exceeded and has at least attempted to cancel
861      * the currently running {@code Statement}
862      * @see #getResultSet
863      * @see #getUpdateCount
864      * @see #getMoreResults
865      * @see #getGeneratedKeys
866      *
867      * @since 1.4
868      */
execute(String sql, int autoGeneratedKeys)869     boolean execute(String sql, int autoGeneratedKeys) throws SQLException;
870 
871     /**
872      * Executes the given SQL statement, which may return multiple results,
873      * and signals the driver that the
874      * auto-generated keys indicated in the given array should be made available
875      * for retrieval.  This array contains the indexes of the columns in the
876      * target table that contain the auto-generated keys that should be made
877      * available.  The driver will ignore the array if the SQL statement
878      * is not an <code>INSERT</code> statement, or an SQL statement able to return
879      * auto-generated keys (the list of such statements is vendor-specific).
880      * <P>
881      * Under some (uncommon) situations, a single SQL statement may return
882      * multiple result sets and/or update counts.  Normally you can ignore
883      * this unless you are (1) executing a stored procedure that you know may
884      * return multiple results or (2) you are dynamically executing an
885      * unknown SQL string.
886      * <P>
887      * The <code>execute</code> method executes an SQL statement and indicates the
888      * form of the first result.  You must then use the methods
889      * <code>getResultSet</code> or <code>getUpdateCount</code>
890      * to retrieve the result, and <code>getMoreResults</code> to
891      * move to any subsequent result(s).
892      *<p>
893      * <strong>Note:</strong>This method cannot be called on a
894      * <code>PreparedStatement</code> or <code>CallableStatement</code>.
895      * @param sql any SQL statement
896      * @param columnIndexes an array of the indexes of the columns in the
897      *        inserted row that should be  made available for retrieval by a
898      *        call to the method <code>getGeneratedKeys</code>
899      * @return <code>true</code> if the first result is a <code>ResultSet</code>
900      *         object; <code>false</code> if it is an update count or there
901      *         are no results
902      * @exception SQLException if a database access error occurs,
903      * this method is called on a closed <code>Statement</code>, the
904      *            elements in the <code>int</code> array passed to this method
905      *            are not valid column indexes, the method is called on a
906      * <code>PreparedStatement</code> or <code>CallableStatement</code>
907      * @throws SQLFeatureNotSupportedException  if the JDBC driver does not support this method
908      * @throws SQLTimeoutException when the driver has determined that the
909      * timeout value that was specified by the {@code setQueryTimeout}
910      * method has been exceeded and has at least attempted to cancel
911      * the currently running {@code Statement}
912      * @see #getResultSet
913      * @see #getUpdateCount
914      * @see #getMoreResults
915      *
916      * @since 1.4
917      */
execute(String sql, int columnIndexes[])918     boolean execute(String sql, int columnIndexes[]) throws SQLException;
919 
920     /**
921      * Executes the given SQL statement, which may return multiple results,
922      * and signals the driver that the
923      * auto-generated keys indicated in the given array should be made available
924      * for retrieval. This array contains the names of the columns in the
925      * target table that contain the auto-generated keys that should be made
926      * available.  The driver will ignore the array if the SQL statement
927      * is not an <code>INSERT</code> statement, or an SQL statement able to return
928      * auto-generated keys (the list of such statements is vendor-specific).
929      * <P>
930      * In some (uncommon) situations, a single SQL statement may return
931      * multiple result sets and/or update counts.  Normally you can ignore
932      * this unless you are (1) executing a stored procedure that you know may
933      * return multiple results or (2) you are dynamically executing an
934      * unknown SQL string.
935      * <P>
936      * The <code>execute</code> method executes an SQL statement and indicates the
937      * form of the first result.  You must then use the methods
938      * <code>getResultSet</code> or <code>getUpdateCount</code>
939      * to retrieve the result, and <code>getMoreResults</code> to
940      * move to any subsequent result(s).
941      *<p>
942      * <strong>Note:</strong>This method cannot be called on a
943      * <code>PreparedStatement</code> or <code>CallableStatement</code>.
944      * @param sql any SQL statement
945      * @param columnNames an array of the names of the columns in the inserted
946      *        row that should be made available for retrieval by a call to the
947      *        method <code>getGeneratedKeys</code>
948      * @return <code>true</code> if the next result is a <code>ResultSet</code>
949      *         object; <code>false</code> if it is an update count or there
950      *         are no more results
951      * @exception SQLException if a database access error occurs,
952      * this method is called on a closed <code>Statement</code>,the
953      *          elements of the <code>String</code> array passed to this
954      *          method are not valid column names, the method is called on a
955      * <code>PreparedStatement</code> or <code>CallableStatement</code>
956      * @throws SQLFeatureNotSupportedException  if the JDBC driver does not support this method
957      * @throws SQLTimeoutException when the driver has determined that the
958      * timeout value that was specified by the {@code setQueryTimeout}
959      * method has been exceeded and has at least attempted to cancel
960      * the currently running {@code Statement}
961      * @see #getResultSet
962      * @see #getUpdateCount
963      * @see #getMoreResults
964      * @see #getGeneratedKeys
965      *
966      * @since 1.4
967      */
execute(String sql, String columnNames[])968     boolean execute(String sql, String columnNames[]) throws SQLException;
969 
970    /**
971      * Retrieves the result set holdability for <code>ResultSet</code> objects
972      * generated by this <code>Statement</code> object.
973      *
974      * @return either <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
975      *         <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
976      * @exception SQLException if a database access error occurs or
977      * this method is called on a closed <code>Statement</code>
978      *
979      * @since 1.4
980      */
getResultSetHoldability()981     int getResultSetHoldability() throws SQLException;
982 
983     /**
984      * Retrieves whether this <code>Statement</code> object has been closed. A <code>Statement</code> is closed if the
985      * method close has been called on it, or if it is automatically closed.
986      * @return true if this <code>Statement</code> object is closed; false if it is still open
987      * @throws SQLException if a database access error occurs
988      * @since 1.6
989      */
isClosed()990     boolean isClosed() throws SQLException;
991 
992         /**
993          * Requests that a <code>Statement</code> be pooled or not pooled.  The value
994          * specified is a hint to the statement pool implementation indicating
995          * whether the applicaiton wants the statement to be pooled.  It is up to
996          * the statement pool manager as to whether the hint is used.
997          * <p>
998          * The poolable value of a statement is applicable to both internal
999          * statement caches implemented by the driver and external statement caches
1000          * implemented by application servers and other applications.
1001          * <p>
1002          * By default, a <code>Statement</code> is not poolable when created, and
1003          * a <code>PreparedStatement</code> and <code>CallableStatement</code>
1004          * are poolable when created.
1005          * <p>
1006          * @param poolable              requests that the statement be pooled if true and
1007          *                                              that the statement not be pooled if false
1008          * <p>
1009          * @throws SQLException if this method is called on a closed
1010          * <code>Statement</code>
1011          * <p>
1012          * @since 1.6
1013          */
setPoolable(boolean poolable)1014         void setPoolable(boolean poolable)
1015                 throws SQLException;
1016 
1017         /**
1018          * Returns a  value indicating whether the <code>Statement</code>
1019          * is poolable or not.
1020          * <p>
1021          * @return              <code>true</code> if the <code>Statement</code>
1022          * is poolable; <code>false</code> otherwise
1023          * <p>
1024          * @throws SQLException if this method is called on a closed
1025          * <code>Statement</code>
1026          * <p>
1027          * @since 1.6
1028          * <p>
1029          * @see java.sql.Statement#setPoolable(boolean) setPoolable(boolean)
1030          */
isPoolable()1031         boolean isPoolable()
1032                 throws SQLException;
1033 
1034     // Android-removed: JDBC 4.1 methods were removed immediately after the initial import.
1035 }
1036