src/share/classes/java/sql/Statement.java

Print this page




 127      * @see #setMaxFieldSize
 128      */
 129     int getMaxFieldSize() throws SQLException;
 130 
 131     /**
 132      * Sets the limit for the maximum number of bytes that can be returned for
 133      * character and binary column values in a <code>ResultSet</code>
 134      * object produced by this <code>Statement</code> object.
 135      *
 136      * This limit applies
 137      * only to <code>BINARY</code>, <code>VARBINARY</code>,
 138      * <code>LONGVARBINARY</code>, <code>CHAR</code>, <code>VARCHAR</code>,
 139      * <code>NCHAR</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code> and
 140      * <code>LONGVARCHAR</code> fields.  If the limit is exceeded, the excess data
 141      * is silently discarded. For maximum portability, use values
 142      * greater than 256.
 143      *
 144      * @param max the new column size limit in bytes; zero means there is no limit
 145      * @exception SQLException if a database access error occurs,
 146      * this method is called on a closed <code>Statement</code>
 147      *            or the condition max >= 0 is not satisfied
 148      * @see #getMaxFieldSize
 149      */
 150     void setMaxFieldSize(int max) throws SQLException;
 151 
 152     /**
 153      * Retrieves the maximum number of rows that a
 154      * <code>ResultSet</code> object produced by this
 155      * <code>Statement</code> object can contain.  If this limit is exceeded,
 156      * the excess rows are silently dropped.
 157      *
 158      * @return the current maximum number of rows for a <code>ResultSet</code>
 159      *         object produced by this <code>Statement</code> object;
 160      *         zero means there is no limit
 161      * @exception SQLException if a database access error occurs or
 162      * this method is called on a closed <code>Statement</code>
 163      * @see #setMaxRows
 164      */
 165     int getMaxRows() throws SQLException;
 166 
 167     /**
 168      * Sets the limit for the maximum number of rows that any
 169      * <code>ResultSet</code> object  generated by this <code>Statement</code>
 170      * object can contain to the given number.
 171      * If the limit is exceeded, the excess
 172      * rows are silently dropped.
 173      *
 174      * @param max the new max rows limit; zero means there is no limit
 175      * @exception SQLException if a database access error occurs,
 176      * this method is called on a closed <code>Statement</code>
 177      *            or the condition max >= 0 is not satisfied
 178      * @see #getMaxRows
 179      */
 180     void setMaxRows(int max) throws SQLException;
 181 
 182     /**
 183      * Sets escape processing on or off.
 184      * If escape scanning is on (the default), the driver will do
 185      * escape substitution before sending the SQL statement to the database.
 186      *<p>
 187      * The {@code Connection} and {@code DataSource} property
 188      * {@code escapeProcessing} may be used to change the default escape processing
 189      * behavior.  A value of true (the default) enables escape Processing for
 190      * all {@code Statement} objects. A value of false disables escape processing
 191      * for all {@code Statement} objects.  The {@code setEscapeProcessing}
 192      * method may be used to specify the escape processing behavior for an
 193      * individual {@code Statement} object.
 194      * <p>
 195      * Note: Since prepared statements have usually been parsed prior
 196      * to making this call, disabling escape processing for
 197      * <code>PreparedStatements</code> objects will have no effect.


 223      *By default there is no limit on the amount of time allowed for a running
 224      * statement to complete. If the limit is exceeded, an
 225      * <code>SQLTimeoutException</code> is thrown.
 226      * A JDBC driver must apply this limit to the <code>execute</code>,
 227      * <code>executeQuery</code> and <code>executeUpdate</code> methods.
 228      * <p>
 229      * <strong>Note:</strong> JDBC driver implementations may also apply this
 230      * limit to {@code ResultSet} methods
 231      * (consult your driver vendor documentation for details).
 232      * <p>
 233      * <strong>Note:</strong> In the case of {@code Statement} batching, it is
 234      * implementation defined as to whether the time-out is applied to
 235      * individual SQL commands added via the {@code addBatch} method or to
 236      * the entire batch of SQL commands invoked by the {@code executeBatch}
 237      * method (consult your driver vendor documentation for details).
 238      *
 239      * @param seconds the new query timeout limit in seconds; zero means
 240      *        there is no limit
 241      * @exception SQLException if a database access error occurs,
 242      * this method is called on a closed <code>Statement</code>
 243      *            or the condition seconds >= 0 is not satisfied
 244      * @see #getQueryTimeout
 245      */
 246     void setQueryTimeout(int seconds) throws SQLException;
 247 
 248     /**
 249      * Cancels this <code>Statement</code> object if both the DBMS and
 250      * driver support aborting an SQL statement.
 251      * This method can be used by one thread to cancel a statement that
 252      * is being executed by another thread.
 253      *
 254      * @exception SQLException if a database access error occurs or
 255      * this method is called on a closed <code>Statement</code>
 256      * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
 257      * this method
 258      */
 259     void cancel() throws SQLException;
 260 
 261     /**
 262      * Retrieves the first warning reported by calls on this <code>Statement</code> object.
 263      * Subsequent <code>Statement</code> object warnings will be chained to this


 368     /**
 369      *  Retrieves the current result as an update count;
 370      *  if the result is a <code>ResultSet</code> object or there are no more results, -1
 371      *  is returned. This method should be called only once per result.
 372      *
 373      * @return the current result as an update count; -1 if the current result is a
 374      * <code>ResultSet</code> object or there are no more results
 375      * @exception SQLException if a database access error occurs or
 376      * this method is called on a closed <code>Statement</code>
 377      * @see #execute
 378      */
 379     int getUpdateCount() throws SQLException;
 380 
 381     /**
 382      * Moves to this <code>Statement</code> object's next result, returns
 383      * <code>true</code> if it is a <code>ResultSet</code> object, and
 384      * implicitly closes any current <code>ResultSet</code>
 385      * object(s) obtained with the method <code>getResultSet</code>.
 386      *
 387      * <P>There are no more results when the following is true:
 388      * <PRE>
 389      *     // stmt is a Statement object
 390      *     ((stmt.getMoreResults() == false) && (stmt.getUpdateCount() == -1))
 391      * </PRE>
 392      *
 393      * @return <code>true</code> if the next result is a <code>ResultSet</code>
 394      *         object; <code>false</code> if it is an update count or there are
 395      *         no more results
 396      * @exception SQLException if a database access error occurs or
 397      * this method is called on a closed <code>Statement</code>
 398      * @see #execute
 399      */
 400     boolean getMoreResults() throws SQLException;
 401 
 402 
 403     //--------------------------JDBC 2.0-----------------------------
 404 
 405 
 406     /**
 407      * Gives the driver a hint as to the direction in which
 408      * rows will be processed in <code>ResultSet</code>
 409      * objects created using this <code>Statement</code> object.  The
 410      * default value is <code>ResultSet.FETCH_FORWARD</code>.
 411      * <P>


 435      *
 436      * @return the default fetch direction for result sets generated
 437      *          from this <code>Statement</code> object
 438      * @exception SQLException if a database access error occurs or
 439      * this method is called on a closed <code>Statement</code>
 440      * @since 1.2
 441      * @see #setFetchDirection
 442      */
 443     int getFetchDirection() throws SQLException;
 444 
 445     /**
 446      * Gives the JDBC driver a hint as to the number of rows that should
 447      * be fetched from the database when more rows are needed for
 448      * <code>ResultSet</code> objects genrated by this <code>Statement</code>.
 449      * If the value specified is zero, then the hint is ignored.
 450      * The default value is zero.
 451      *
 452      * @param rows the number of rows to fetch
 453      * @exception SQLException if a database access error occurs,
 454      * this method is called on a closed <code>Statement</code> or the
 455      *        condition  <code>rows >= 0</code> is not satisfied.
 456      * @since 1.2
 457      * @see #getFetchSize
 458      */
 459     void setFetchSize(int rows) throws SQLException;
 460 
 461     /**
 462      * Retrieves the number of result set rows that is the default
 463      * fetch size for <code>ResultSet</code> objects
 464      * generated from this <code>Statement</code> object.
 465      * If this <code>Statement</code> object has not set
 466      * a fetch size by calling the method <code>setFetchSize</code>,
 467      * the return value is implementation-specific.
 468      *
 469      * @return the default fetch size for result sets generated
 470      *          from this <code>Statement</code> object
 471      * @exception SQLException if a database access error occurs or
 472      * this method is called on a closed <code>Statement</code>
 473      * @since 1.2
 474      * @see #setFetchSize
 475      */


 648      *
 649      * @since 1.4
 650      */
 651     int RETURN_GENERATED_KEYS = 1;
 652 
 653     /**
 654      * The constant indicating that generated keys should not be made
 655      * available for retrieval.
 656      *
 657      * @since 1.4
 658      */
 659     int NO_GENERATED_KEYS = 2;
 660 
 661     /**
 662      * Moves to this <code>Statement</code> object's next result, deals with
 663      * any current <code>ResultSet</code> object(s) according  to the instructions
 664      * specified by the given flag, and returns
 665      * <code>true</code> if the next result is a <code>ResultSet</code> object.
 666      *
 667      * <P>There are no more results when the following is true:
 668      * <PRE>
 669      *     // stmt is a Statement object
 670      *     ((stmt.getMoreResults(current) == false) && (stmt.getUpdateCount() == -1))
 671      * </PRE>
 672      *
 673      * @param current one of the following <code>Statement</code>
 674      *        constants indicating what should happen to current
 675      *        <code>ResultSet</code> objects obtained using the method
 676      *        <code>getResultSet</code>:
 677      *        <code>Statement.CLOSE_CURRENT_RESULT</code>,
 678      *        <code>Statement.KEEP_CURRENT_RESULT</code>, or
 679      *        <code>Statement.CLOSE_ALL_RESULTS</code>
 680      * @return <code>true</code> if the next result is a <code>ResultSet</code>
 681      *         object; <code>false</code> if it is an update count or there are no
 682      *         more results
 683      * @exception SQLException if a database access error occurs,
 684      * this method is called on a closed <code>Statement</code> or the argument
 685          *         supplied is not one of the following:
 686      *        <code>Statement.CLOSE_CURRENT_RESULT</code>,
 687      *        <code>Statement.KEEP_CURRENT_RESULT</code> or
 688      *        <code>Statement.CLOSE_ALL_RESULTS</code>
 689      *@exception SQLFeatureNotSupportedException if
 690      * <code>DatabaseMetaData.supportsMultipleOpenResults</code> returns
 691      * <code>false</code> and either


1090      */
1091     default long getLargeUpdateCount() throws SQLException {
1092         throw new UnsupportedOperationException("getLargeUpdateCount not implemented");
1093     }
1094 
1095     /**
1096      * Sets the limit for the maximum number of rows that any
1097      * <code>ResultSet</code> object  generated by this <code>Statement</code>
1098      * object can contain to the given number.
1099      * If the limit is exceeded, the excess
1100      * rows are silently dropped.
1101      * <p>
1102      * This method should be used when the row limit may exceed
1103      * {@link Integer#MAX_VALUE}.
1104      *<p>
1105      * The default implementation will throw {@code UnsupportedOperationException}
1106      *
1107      * @param max the new max rows limit; zero means there is no limit
1108      * @exception SQLException if a database access error occurs,
1109      * this method is called on a closed <code>Statement</code>
1110      *            or the condition max >= 0 is not satisfied
1111      * @see #getMaxRows
1112      * @since 1.8
1113      */
1114     default void setLargeMaxRows(long max) throws SQLException {
1115         throw new UnsupportedOperationException("setLargeMaxRows not implemented");
1116     }
1117 
1118     /**
1119      * Retrieves the maximum number of rows that a
1120      * <code>ResultSet</code> object produced by this
1121      * <code>Statement</code> object can contain.  If this limit is exceeded,
1122      * the excess rows are silently dropped.
1123      * <p>
1124      * This method should be used when the returned row limit may exceed
1125      * {@link Integer#MAX_VALUE}.
1126      *<p>
1127      * The default implementation will return {@code 0}
1128      *
1129      * @return the current maximum number of rows for a <code>ResultSet</code>
1130      *         object produced by this <code>Statement</code> object;




 127      * @see #setMaxFieldSize
 128      */
 129     int getMaxFieldSize() throws SQLException;
 130 
 131     /**
 132      * Sets the limit for the maximum number of bytes that can be returned for
 133      * character and binary column values in a <code>ResultSet</code>
 134      * object produced by this <code>Statement</code> object.
 135      *
 136      * This limit applies
 137      * only to <code>BINARY</code>, <code>VARBINARY</code>,
 138      * <code>LONGVARBINARY</code>, <code>CHAR</code>, <code>VARCHAR</code>,
 139      * <code>NCHAR</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code> and
 140      * <code>LONGVARCHAR</code> fields.  If the limit is exceeded, the excess data
 141      * is silently discarded. For maximum portability, use values
 142      * greater than 256.
 143      *
 144      * @param max the new column size limit in bytes; zero means there is no limit
 145      * @exception SQLException if a database access error occurs,
 146      * this method is called on a closed <code>Statement</code>
 147      *            or the condition {@code max >= 0} is not satisfied
 148      * @see #getMaxFieldSize
 149      */
 150     void setMaxFieldSize(int max) throws SQLException;
 151 
 152     /**
 153      * Retrieves the maximum number of rows that a
 154      * <code>ResultSet</code> object produced by this
 155      * <code>Statement</code> object can contain.  If this limit is exceeded,
 156      * the excess rows are silently dropped.
 157      *
 158      * @return the current maximum number of rows for a <code>ResultSet</code>
 159      *         object produced by this <code>Statement</code> object;
 160      *         zero means there is no limit
 161      * @exception SQLException if a database access error occurs or
 162      * this method is called on a closed <code>Statement</code>
 163      * @see #setMaxRows
 164      */
 165     int getMaxRows() throws SQLException;
 166 
 167     /**
 168      * Sets the limit for the maximum number of rows that any
 169      * <code>ResultSet</code> object  generated by this <code>Statement</code>
 170      * object can contain to the given number.
 171      * If the limit is exceeded, the excess
 172      * rows are silently dropped.
 173      *
 174      * @param max the new max rows limit; zero means there is no limit
 175      * @exception SQLException if a database access error occurs,
 176      * this method is called on a closed <code>Statement</code>
 177      *            or the condition {@code max >= 0} is not satisfied
 178      * @see #getMaxRows
 179      */
 180     void setMaxRows(int max) throws SQLException;
 181 
 182     /**
 183      * Sets escape processing on or off.
 184      * If escape scanning is on (the default), the driver will do
 185      * escape substitution before sending the SQL statement to the database.
 186      *<p>
 187      * The {@code Connection} and {@code DataSource} property
 188      * {@code escapeProcessing} may be used to change the default escape processing
 189      * behavior.  A value of true (the default) enables escape Processing for
 190      * all {@code Statement} objects. A value of false disables escape processing
 191      * for all {@code Statement} objects.  The {@code setEscapeProcessing}
 192      * method may be used to specify the escape processing behavior for an
 193      * individual {@code Statement} object.
 194      * <p>
 195      * Note: Since prepared statements have usually been parsed prior
 196      * to making this call, disabling escape processing for
 197      * <code>PreparedStatements</code> objects will have no effect.


 223      *By default there is no limit on the amount of time allowed for a running
 224      * statement to complete. If the limit is exceeded, an
 225      * <code>SQLTimeoutException</code> is thrown.
 226      * A JDBC driver must apply this limit to the <code>execute</code>,
 227      * <code>executeQuery</code> and <code>executeUpdate</code> methods.
 228      * <p>
 229      * <strong>Note:</strong> JDBC driver implementations may also apply this
 230      * limit to {@code ResultSet} methods
 231      * (consult your driver vendor documentation for details).
 232      * <p>
 233      * <strong>Note:</strong> In the case of {@code Statement} batching, it is
 234      * implementation defined as to whether the time-out is applied to
 235      * individual SQL commands added via the {@code addBatch} method or to
 236      * the entire batch of SQL commands invoked by the {@code executeBatch}
 237      * method (consult your driver vendor documentation for details).
 238      *
 239      * @param seconds the new query timeout limit in seconds; zero means
 240      *        there is no limit
 241      * @exception SQLException if a database access error occurs,
 242      * this method is called on a closed <code>Statement</code>
 243      *            or the condition {@code seconds >= 0} is not satisfied
 244      * @see #getQueryTimeout
 245      */
 246     void setQueryTimeout(int seconds) throws SQLException;
 247 
 248     /**
 249      * Cancels this <code>Statement</code> object if both the DBMS and
 250      * driver support aborting an SQL statement.
 251      * This method can be used by one thread to cancel a statement that
 252      * is being executed by another thread.
 253      *
 254      * @exception SQLException if a database access error occurs or
 255      * this method is called on a closed <code>Statement</code>
 256      * @exception SQLFeatureNotSupportedException if the JDBC driver does not support
 257      * this method
 258      */
 259     void cancel() throws SQLException;
 260 
 261     /**
 262      * Retrieves the first warning reported by calls on this <code>Statement</code> object.
 263      * Subsequent <code>Statement</code> object warnings will be chained to this


 368     /**
 369      *  Retrieves the current result as an update count;
 370      *  if the result is a <code>ResultSet</code> object or there are no more results, -1
 371      *  is returned. This method should be called only once per result.
 372      *
 373      * @return the current result as an update count; -1 if the current result is a
 374      * <code>ResultSet</code> object or there are no more results
 375      * @exception SQLException if a database access error occurs or
 376      * this method is called on a closed <code>Statement</code>
 377      * @see #execute
 378      */
 379     int getUpdateCount() throws SQLException;
 380 
 381     /**
 382      * Moves to this <code>Statement</code> object's next result, returns
 383      * <code>true</code> if it is a <code>ResultSet</code> object, and
 384      * implicitly closes any current <code>ResultSet</code>
 385      * object(s) obtained with the method <code>getResultSet</code>.
 386      *
 387      * <P>There are no more results when the following is true:
 388      * <PRE>{@code
 389      *     // stmt is a Statement object
 390      *     ((stmt.getMoreResults() == false) && (stmt.getUpdateCount() == -1))
 391      * }</PRE>
 392      *
 393      * @return <code>true</code> if the next result is a <code>ResultSet</code>
 394      *         object; <code>false</code> if it is an update count or there are
 395      *         no more results
 396      * @exception SQLException if a database access error occurs or
 397      * this method is called on a closed <code>Statement</code>
 398      * @see #execute
 399      */
 400     boolean getMoreResults() throws SQLException;
 401 
 402 
 403     //--------------------------JDBC 2.0-----------------------------
 404 
 405 
 406     /**
 407      * Gives the driver a hint as to the direction in which
 408      * rows will be processed in <code>ResultSet</code>
 409      * objects created using this <code>Statement</code> object.  The
 410      * default value is <code>ResultSet.FETCH_FORWARD</code>.
 411      * <P>


 435      *
 436      * @return the default fetch direction for result sets generated
 437      *          from this <code>Statement</code> object
 438      * @exception SQLException if a database access error occurs or
 439      * this method is called on a closed <code>Statement</code>
 440      * @since 1.2
 441      * @see #setFetchDirection
 442      */
 443     int getFetchDirection() throws SQLException;
 444 
 445     /**
 446      * Gives the JDBC driver a hint as to the number of rows that should
 447      * be fetched from the database when more rows are needed for
 448      * <code>ResultSet</code> objects genrated by this <code>Statement</code>.
 449      * If the value specified is zero, then the hint is ignored.
 450      * The default value is zero.
 451      *
 452      * @param rows the number of rows to fetch
 453      * @exception SQLException if a database access error occurs,
 454      * this method is called on a closed <code>Statement</code> or the
 455      *        condition {@code rows >= 0} is not satisfied.
 456      * @since 1.2
 457      * @see #getFetchSize
 458      */
 459     void setFetchSize(int rows) throws SQLException;
 460 
 461     /**
 462      * Retrieves the number of result set rows that is the default
 463      * fetch size for <code>ResultSet</code> objects
 464      * generated from this <code>Statement</code> object.
 465      * If this <code>Statement</code> object has not set
 466      * a fetch size by calling the method <code>setFetchSize</code>,
 467      * the return value is implementation-specific.
 468      *
 469      * @return the default fetch size for result sets generated
 470      *          from this <code>Statement</code> object
 471      * @exception SQLException if a database access error occurs or
 472      * this method is called on a closed <code>Statement</code>
 473      * @since 1.2
 474      * @see #setFetchSize
 475      */


 648      *
 649      * @since 1.4
 650      */
 651     int RETURN_GENERATED_KEYS = 1;
 652 
 653     /**
 654      * The constant indicating that generated keys should not be made
 655      * available for retrieval.
 656      *
 657      * @since 1.4
 658      */
 659     int NO_GENERATED_KEYS = 2;
 660 
 661     /**
 662      * Moves to this <code>Statement</code> object's next result, deals with
 663      * any current <code>ResultSet</code> object(s) according  to the instructions
 664      * specified by the given flag, and returns
 665      * <code>true</code> if the next result is a <code>ResultSet</code> object.
 666      *
 667      * <P>There are no more results when the following is true:
 668      * <PRE>{@code
 669      *     // stmt is a Statement object
 670      *     ((stmt.getMoreResults(current) == false) && (stmt.getUpdateCount() == -1))
 671      * }</PRE>
 672      *
 673      * @param current one of the following <code>Statement</code>
 674      *        constants indicating what should happen to current
 675      *        <code>ResultSet</code> objects obtained using the method
 676      *        <code>getResultSet</code>:
 677      *        <code>Statement.CLOSE_CURRENT_RESULT</code>,
 678      *        <code>Statement.KEEP_CURRENT_RESULT</code>, or
 679      *        <code>Statement.CLOSE_ALL_RESULTS</code>
 680      * @return <code>true</code> if the next result is a <code>ResultSet</code>
 681      *         object; <code>false</code> if it is an update count or there are no
 682      *         more results
 683      * @exception SQLException if a database access error occurs,
 684      * this method is called on a closed <code>Statement</code> or the argument
 685          *         supplied is not one of the following:
 686      *        <code>Statement.CLOSE_CURRENT_RESULT</code>,
 687      *        <code>Statement.KEEP_CURRENT_RESULT</code> or
 688      *        <code>Statement.CLOSE_ALL_RESULTS</code>
 689      *@exception SQLFeatureNotSupportedException if
 690      * <code>DatabaseMetaData.supportsMultipleOpenResults</code> returns
 691      * <code>false</code> and either


1090      */
1091     default long getLargeUpdateCount() throws SQLException {
1092         throw new UnsupportedOperationException("getLargeUpdateCount not implemented");
1093     }
1094 
1095     /**
1096      * Sets the limit for the maximum number of rows that any
1097      * <code>ResultSet</code> object  generated by this <code>Statement</code>
1098      * object can contain to the given number.
1099      * If the limit is exceeded, the excess
1100      * rows are silently dropped.
1101      * <p>
1102      * This method should be used when the row limit may exceed
1103      * {@link Integer#MAX_VALUE}.
1104      *<p>
1105      * The default implementation will throw {@code UnsupportedOperationException}
1106      *
1107      * @param max the new max rows limit; zero means there is no limit
1108      * @exception SQLException if a database access error occurs,
1109      * this method is called on a closed <code>Statement</code>
1110      *            or the condition {@code max >= 0} is not satisfied
1111      * @see #getMaxRows
1112      * @since 1.8
1113      */
1114     default void setLargeMaxRows(long max) throws SQLException {
1115         throw new UnsupportedOperationException("setLargeMaxRows not implemented");
1116     }
1117 
1118     /**
1119      * Retrieves the maximum number of rows that a
1120      * <code>ResultSet</code> object produced by this
1121      * <code>Statement</code> object can contain.  If this limit is exceeded,
1122      * the excess rows are silently dropped.
1123      * <p>
1124      * This method should be used when the returned row limit may exceed
1125      * {@link Integer#MAX_VALUE}.
1126      *<p>
1127      * The default implementation will return {@code 0}
1128      *
1129      * @return the current maximum number of rows for a <code>ResultSet</code>
1130      *         object produced by this <code>Statement</code> object;