Path: blob/master/src/java.sql/share/classes/java/sql/Statement.java
41153 views
/*1* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.sql;2627import java.util.regex.Pattern;28import static java.util.stream.Collectors.joining;2930/**31* <P>The object used for executing a static SQL statement32* and returning the results it produces.33* <P>34* By default, only one {@code ResultSet} object per {@code Statement}35* object can be open at the same time. Therefore, if the reading of one36* {@code ResultSet} object is interleaved37* with the reading of another, each must have been generated by38* different {@code Statement} objects. All execution methods in the39* {@code Statement} interface implicitly close a current40* {@code ResultSet} object of the statement if an open one exists.41*42* @see Connection#createStatement43* @see ResultSet44* @since 1.145*/46public interface Statement extends Wrapper, AutoCloseable {4748/**49* Executes the given SQL statement, which returns a single50* {@code ResultSet} object.51*<p>52* <strong>Note:</strong>This method cannot be called on a53* {@code PreparedStatement} or {@code CallableStatement}.54* @param sql an SQL statement to be sent to the database, typically a55* static SQL {@code SELECT} statement56* @return a {@code ResultSet} object that contains the data produced57* by the given query; never {@code null}58* @throws SQLException if a database access error occurs,59* this method is called on a closed {@code Statement}, the given60* SQL statement produces anything other than a single61* {@code ResultSet} object, the method is called on a62* {@code PreparedStatement} or {@code CallableStatement}63* @throws SQLTimeoutException when the driver has determined that the64* timeout value that was specified by the {@code setQueryTimeout}65* method has been exceeded and has at least attempted to cancel66* the currently running {@code Statement}67*/68ResultSet executeQuery(String sql) throws SQLException;6970/**71* Executes the given SQL statement, which may be an {@code INSERT},72* {@code UPDATE}, or {@code DELETE} statement or an73* SQL statement that returns nothing, such as an SQL DDL statement.74*<p>75* <strong>Note:</strong>This method cannot be called on a76* {@code PreparedStatement} or {@code CallableStatement}.77* @param sql an SQL Data Manipulation Language (DML) statement, such as {@code INSERT}, {@code UPDATE} or78* {@code DELETE}; or an SQL statement that returns nothing,79* such as a DDL statement.80*81* @return either (1) the row count for SQL Data Manipulation Language (DML) statements82* or (2) 0 for SQL statements that return nothing83*84* @throws SQLException if a database access error occurs,85* this method is called on a closed {@code Statement}, the given86* SQL statement produces a {@code ResultSet} object, the method is called on a87* {@code PreparedStatement} or {@code CallableStatement}88* @throws SQLTimeoutException when the driver has determined that the89* timeout value that was specified by the {@code setQueryTimeout}90* method has been exceeded and has at least attempted to cancel91* the currently running {@code Statement}92*/93int executeUpdate(String sql) throws SQLException;9495/**96* Releases this {@code Statement} object's database97* and JDBC resources immediately instead of waiting for98* this to happen when it is automatically closed.99* It is generally good practice to release resources as soon as100* you are finished with them to avoid tying up database101* resources.102* <P>103* Calling the method {@code close} on a {@code Statement}104* object that is already closed has no effect.105* <P>106* <B>Note:</B>When a {@code Statement} object is107* closed, its current {@code ResultSet} object, if one exists, is108* also closed.109*110* @throws SQLException if a database access error occurs111*/112void close() throws SQLException;113114//----------------------------------------------------------------------115116/**117* Retrieves the maximum number of bytes that can be118* returned for character and binary column values in a {@code ResultSet}119* object produced by this {@code Statement} object.120* This limit applies only to {@code BINARY}, {@code VARBINARY},121* {@code LONGVARBINARY}, {@code CHAR}, {@code VARCHAR},122* {@code NCHAR}, {@code NVARCHAR}, {@code LONGNVARCHAR}123* and {@code LONGVARCHAR} columns. If the limit is exceeded, the124* excess data is silently discarded.125*126* @return the current column size limit for columns storing character and127* binary values; zero means there is no limit128* @throws SQLException if a database access error occurs or129* this method is called on a closed {@code Statement}130* @see #setMaxFieldSize131*/132int getMaxFieldSize() throws SQLException;133134/**135* Sets the limit for the maximum number of bytes that can be returned for136* character and binary column values in a {@code ResultSet}137* object produced by this {@code Statement} object.138*139* This limit applies140* only to {@code BINARY}, {@code VARBINARY},141* {@code LONGVARBINARY}, {@code CHAR}, {@code VARCHAR},142* {@code NCHAR}, {@code NVARCHAR}, {@code LONGNVARCHAR} and143* {@code LONGVARCHAR} fields. If the limit is exceeded, the excess data144* is silently discarded. For maximum portability, use values145* greater than 256.146*147* @param max the new column size limit in bytes; zero means there is no limit148* @throws SQLException if a database access error occurs,149* this method is called on a closed {@code Statement}150* or the condition {@code max >= 0} is not satisfied151* @see #getMaxFieldSize152*/153void setMaxFieldSize(int max) throws SQLException;154155/**156* Retrieves the maximum number of rows that a157* {@code ResultSet} object produced by this158* {@code Statement} object can contain. If this limit is exceeded,159* the excess rows are silently dropped.160*161* @return the current maximum number of rows for a {@code ResultSet}162* object produced by this {@code Statement} object;163* zero means there is no limit164* @throws SQLException if a database access error occurs or165* this method is called on a closed {@code Statement}166* @see #setMaxRows167*/168int getMaxRows() throws SQLException;169170/**171* Sets the limit for the maximum number of rows that any172* {@code ResultSet} object generated by this {@code Statement}173* object can contain to the given number.174* If the limit is exceeded, the excess175* rows are silently dropped.176*177* @param max the new max rows limit; zero means there is no limit178* @throws SQLException if a database access error occurs,179* this method is called on a closed {@code Statement}180* or the condition {@code max >= 0} is not satisfied181* @see #getMaxRows182*/183void setMaxRows(int max) throws SQLException;184185/**186* Sets escape processing on or off.187* If escape scanning is on (the default), the driver will do188* escape substitution before sending the SQL statement to the database.189*<p>190* The {@code Connection} and {@code DataSource} property191* {@code escapeProcessing} may be used to change the default escape processing192* behavior. A value of true (the default) enables escape Processing for193* all {@code Statement} objects. A value of false disables escape processing194* for all {@code Statement} objects. The {@code setEscapeProcessing}195* method may be used to specify the escape processing behavior for an196* individual {@code Statement} object.197* <p>198* Note: Since prepared statements have usually been parsed prior199* to making this call, disabling escape processing for200* {@code PreparedStatements} objects will have no effect.201*202* @param enable {@code true} to enable escape processing;203* {@code false} to disable it204* @throws SQLException if a database access error occurs or205* this method is called on a closed {@code Statement}206*/207void setEscapeProcessing(boolean enable) throws SQLException;208209/**210* Retrieves the number of seconds the driver will211* wait for a {@code Statement} object to execute.212* If the limit is exceeded, a213* {@code SQLException} is thrown.214*215* @return the current query timeout limit in seconds; zero means there is216* no limit217* @throws SQLException if a database access error occurs or218* this method is called on a closed {@code Statement}219* @see #setQueryTimeout220*/221int getQueryTimeout() throws SQLException;222223/**224* Sets the number of seconds the driver will wait for a225* {@code Statement} object to execute to the given number of seconds.226*By default there is no limit on the amount of time allowed for a running227* statement to complete. If the limit is exceeded, an228* {@code SQLTimeoutException} is thrown.229* A JDBC driver must apply this limit to the {@code execute},230* {@code executeQuery} and {@code executeUpdate} methods.231* <p>232* <strong>Note:</strong> JDBC driver implementations may also apply this233* limit to {@code ResultSet} methods234* (consult your driver vendor documentation for details).235* <p>236* <strong>Note:</strong> In the case of {@code Statement} batching, it is237* implementation defined as to whether the time-out is applied to238* individual SQL commands added via the {@code addBatch} method or to239* the entire batch of SQL commands invoked by the {@code executeBatch}240* method (consult your driver vendor documentation for details).241*242* @param seconds the new query timeout limit in seconds; zero means243* there is no limit244* @throws SQLException if a database access error occurs,245* this method is called on a closed {@code Statement}246* or the condition {@code seconds >= 0} is not satisfied247* @see #getQueryTimeout248*/249void setQueryTimeout(int seconds) throws SQLException;250251/**252* Cancels this {@code Statement} object if both the DBMS and253* driver support aborting an SQL statement.254* This method can be used by one thread to cancel a statement that255* is being executed by another thread.256*257* @throws SQLException if a database access error occurs or258* this method is called on a closed {@code Statement}259* @throws SQLFeatureNotSupportedException if the JDBC driver does not support260* this method261*/262void cancel() throws SQLException;263264/**265* Retrieves the first warning reported by calls on this {@code Statement} object.266* Subsequent {@code Statement} object warnings will be chained to this267* {@code SQLWarning} object.268*269* <p>The warning chain is automatically cleared each time270* a statement is (re)executed. This method may not be called on a closed271* {@code Statement} object; doing so will cause an {@code SQLException}272* to be thrown.273*274* <P><B>Note:</B> If you are processing a {@code ResultSet} object, any275* warnings associated with reads on that {@code ResultSet} object276* will be chained on it rather than on the {@code Statement}277* object that produced it.278*279* @return the first {@code SQLWarning} object or {@code null}280* if there are no warnings281* @throws SQLException if a database access error occurs or282* this method is called on a closed {@code Statement}283*/284SQLWarning getWarnings() throws SQLException;285286/**287* Clears all the warnings reported on this {@code Statement}288* object. After a call to this method,289* the method {@code getWarnings} will return290* {@code null} until a new warning is reported for this291* {@code Statement} object.292*293* @throws SQLException if a database access error occurs or294* this method is called on a closed {@code Statement}295*/296void clearWarnings() throws SQLException;297298/**299* Sets the SQL cursor name to the given {@code String}, which300* will be used by subsequent {@code Statement} object301* {@code execute} methods. This name can then be302* used in SQL positioned update or delete statements to identify the303* current row in the {@code ResultSet} object generated by this304* statement. If the database does not support positioned update/delete,305* this method is a noop. To insure that a cursor has the proper isolation306* level to support updates, the cursor's {@code SELECT} statement307* should have the form {@code SELECT FOR UPDATE}. If308* {@code FOR UPDATE} is not present, positioned updates may fail.309*310* <P><B>Note:</B> By definition, the execution of positioned updates and311* deletes must be done by a different {@code Statement} object than312* the one that generated the {@code ResultSet} object being used for313* positioning. Also, cursor names must be unique within a connection.314*315* @param name the new cursor name, which must be unique within316* a connection317* @throws SQLException if a database access error occurs or318* this method is called on a closed {@code Statement}319* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method320*/321void setCursorName(String name) throws SQLException;322323//----------------------- Multiple Results --------------------------324325/**326* Executes the given SQL statement, which may return multiple results.327* In some (uncommon) situations, a single SQL statement may return328* multiple result sets and/or update counts. Normally you can ignore329* this unless you are (1) executing a stored procedure that you know may330* return multiple results or (2) you are dynamically executing an331* unknown SQL string.332* <P>333* The {@code execute} method executes an SQL statement and indicates the334* form of the first result. You must then use the methods335* {@code getResultSet} or {@code getUpdateCount}336* to retrieve the result, and {@code getMoreResults} to337* move to any subsequent result(s).338* <p>339*<strong>Note:</strong>This method cannot be called on a340* {@code PreparedStatement} or {@code CallableStatement}.341* @param sql any SQL statement342* @return {@code true} if the first result is a {@code ResultSet}343* object; {@code false} if it is an update count or there are344* no results345* @throws SQLException if a database access error occurs,346* this method is called on a closed {@code Statement},347* the method is called on a348* {@code PreparedStatement} or {@code CallableStatement}349* @throws SQLTimeoutException when the driver has determined that the350* timeout value that was specified by the {@code setQueryTimeout}351* method has been exceeded and has at least attempted to cancel352* the currently running {@code Statement}353* @see #getResultSet354* @see #getUpdateCount355* @see #getMoreResults356*/357boolean execute(String sql) throws SQLException;358359/**360* Retrieves the current result as a {@code ResultSet} object.361* This method should be called only once per result.362*363* @return the current result as a {@code ResultSet} object or364* {@code null} if the result is an update count or there are no more results365* @throws SQLException if a database access error occurs or366* this method is called on a closed {@code Statement}367* @see #execute368*/369ResultSet getResultSet() throws SQLException;370371/**372* Retrieves the current result as an update count;373* if the result is a {@code ResultSet} object or there are no more results, -1374* is returned. This method should be called only once per result.375*376* @return the current result as an update count; -1 if the current result is a377* {@code ResultSet} object or there are no more results378* @throws SQLException if a database access error occurs or379* this method is called on a closed {@code Statement}380* @see #execute381*/382int getUpdateCount() throws SQLException;383384/**385* Moves to this {@code Statement} object's next result, returns386* {@code true} if it is a {@code ResultSet} object, and387* implicitly closes any current {@code ResultSet}388* object(s) obtained with the method {@code getResultSet}.389*390* <P>There are no more results when the following is true:391* <PRE>{@code392* // stmt is a Statement object393* ((stmt.getMoreResults() == false) && (stmt.getUpdateCount() == -1))394* }</PRE>395*396* @return {@code true} if the next result is a {@code ResultSet}397* object; {@code false} if it is an update count or there are398* no more results399* @throws SQLException if a database access error occurs or400* this method is called on a closed {@code Statement}401* @see #execute402*/403boolean getMoreResults() throws SQLException;404405406//--------------------------JDBC 2.0-----------------------------407408409/**410* Gives the driver a hint as to the direction in which411* rows will be processed in {@code ResultSet}412* objects created using this {@code Statement} object. The413* default value is {@code ResultSet.FETCH_FORWARD}.414* <P>415* Note that this method sets the default fetch direction for416* result sets generated by this {@code Statement} object.417* Each result set has its own methods for getting and setting418* its own fetch direction.419*420* @param direction the initial direction for processing rows421* @throws SQLException if a database access error occurs,422* this method is called on a closed {@code Statement}423* or the given direction424* is not one of {@code ResultSet.FETCH_FORWARD},425* {@code ResultSet.FETCH_REVERSE}, or {@code ResultSet.FETCH_UNKNOWN}426* @since 1.2427* @see #getFetchDirection428*/429void setFetchDirection(int direction) throws SQLException;430431/**432* Retrieves the direction for fetching rows from433* database tables that is the default for result sets434* generated from this {@code Statement} object.435* If this {@code Statement} object has not set436* a fetch direction by calling the method {@code setFetchDirection},437* the return value is implementation-specific.438*439* @return the default fetch direction for result sets generated440* from this {@code Statement} object441* @throws SQLException if a database access error occurs or442* this method is called on a closed {@code Statement}443* @since 1.2444* @see #setFetchDirection445*/446int getFetchDirection() throws SQLException;447448/**449* Gives the JDBC driver a hint as to the number of rows that should450* be fetched from the database when more rows are needed for451* {@code ResultSet} objects generated by this {@code Statement}.452* If the value specified is zero, then the hint is ignored.453* The default value is zero.454*455* @param rows the number of rows to fetch456* @throws SQLException if a database access error occurs,457* this method is called on a closed {@code Statement} or the458* condition {@code rows >= 0} is not satisfied.459* @since 1.2460* @see #getFetchSize461*/462void setFetchSize(int rows) throws SQLException;463464/**465* Retrieves the number of result set rows that is the default466* fetch size for {@code ResultSet} objects467* generated from this {@code Statement} object.468* If this {@code Statement} object has not set469* a fetch size by calling the method {@code setFetchSize},470* the return value is implementation-specific.471*472* @return the default fetch size for result sets generated473* from this {@code Statement} object474* @throws SQLException if a database access error occurs or475* this method is called on a closed {@code Statement}476* @since 1.2477* @see #setFetchSize478*/479int getFetchSize() throws SQLException;480481/**482* Retrieves the result set concurrency for {@code ResultSet} objects483* generated by this {@code Statement} object.484*485* @return either {@code ResultSet.CONCUR_READ_ONLY} or486* {@code ResultSet.CONCUR_UPDATABLE}487* @throws SQLException if a database access error occurs or488* this method is called on a closed {@code Statement}489* @since 1.2490*/491int getResultSetConcurrency() throws SQLException;492493/**494* Retrieves the result set type for {@code ResultSet} objects495* generated by this {@code Statement} object.496*497* @return one of {@code ResultSet.TYPE_FORWARD_ONLY},498* {@code ResultSet.TYPE_SCROLL_INSENSITIVE}, or499* {@code ResultSet.TYPE_SCROLL_SENSITIVE}500* @throws SQLException if a database access error occurs or501* this method is called on a closed {@code Statement}502* @since 1.2503*/504int getResultSetType() throws SQLException;505506/**507* Adds the given SQL command to the current list of commands for this508* {@code Statement} object. The commands in this list can be509* executed as a batch by calling the method {@code executeBatch}.510* <P>511*<strong>Note:</strong>This method cannot be called on a512* {@code PreparedStatement} or {@code CallableStatement}.513* @param sql typically this is a SQL {@code INSERT} or514* {@code UPDATE} statement515* @throws SQLException if a database access error occurs,516* this method is called on a closed {@code Statement}, the517* driver does not support batch updates, the method is called on a518* {@code PreparedStatement} or {@code CallableStatement}519* @see #executeBatch520* @see DatabaseMetaData#supportsBatchUpdates521* @since 1.2522*/523void addBatch( String sql ) throws SQLException;524525/**526* Empties this {@code Statement} object's current list of527* SQL commands.528*529* @throws SQLException if a database access error occurs,530* this method is called on a closed {@code Statement} or the531* driver does not support batch updates532* @see #addBatch533* @see DatabaseMetaData#supportsBatchUpdates534* @since 1.2535*/536void clearBatch() throws SQLException;537538/**539* Submits a batch of commands to the database for execution and540* if all commands execute successfully, returns an array of update counts.541* The {@code int} elements of the array that is returned are ordered542* to correspond to the commands in the batch, which are ordered543* according to the order in which they were added to the batch.544* The elements in the array returned by the method {@code executeBatch}545* may be one of the following:546* <OL>547* <LI>A number greater than or equal to zero -- indicates that the548* command was processed successfully and is an update count giving the549* number of rows in the database that were affected by the command's550* execution551* <LI>A value of {@code SUCCESS_NO_INFO} -- indicates that the command was552* processed successfully but that the number of rows affected is553* unknown554* <P>555* If one of the commands in a batch update fails to execute properly,556* this method throws a {@code BatchUpdateException}, and a JDBC557* driver may or may not continue to process the remaining commands in558* the batch. However, the driver's behavior must be consistent with a559* particular DBMS, either always continuing to process commands or never560* continuing to process commands. If the driver continues processing561* after a failure, the array returned by the method562* {@code BatchUpdateException.getUpdateCounts}563* will contain as many elements as there are commands in the batch, and564* at least one of the elements will be the following:565*566* <LI>A value of {@code EXECUTE_FAILED} -- indicates that the command failed567* to execute successfully and occurs only if a driver continues to568* process commands after a command fails569* </OL>570* <P>571* The possible implementations and return values have been modified in572* the Java 2 SDK, Standard Edition, version 1.3 to573* accommodate the option of continuing to process commands in a batch574* update after a {@code BatchUpdateException} object has been thrown.575*576* @return an array of update counts containing one element for each577* command in the batch. The elements of the array are ordered according578* to the order in which commands were added to the batch.579* @throws SQLException if a database access error occurs,580* this method is called on a closed {@code Statement} or the581* driver does not support batch statements. Throws {@link BatchUpdateException}582* (a subclass of {@code SQLException}) if one of the commands sent to the583* database fails to execute properly or attempts to return a result set.584* @throws SQLTimeoutException when the driver has determined that the585* timeout value that was specified by the {@code setQueryTimeout}586* method has been exceeded and has at least attempted to cancel587* the currently running {@code Statement}588*589* @see #addBatch590* @see DatabaseMetaData#supportsBatchUpdates591* @since 1.2592*/593int[] executeBatch() throws SQLException;594595/**596* Retrieves the {@code Connection} object597* that produced this {@code Statement} object.598* @return the connection that produced this statement599* @throws SQLException if a database access error occurs or600* this method is called on a closed {@code Statement}601* @since 1.2602*/603Connection getConnection() throws SQLException;604605//--------------------------JDBC 3.0-----------------------------606607/**608* The constant indicating that the current {@code ResultSet} object609* should be closed when calling {@code getMoreResults}.610*611* @since 1.4612*/613int CLOSE_CURRENT_RESULT = 1;614615/**616* The constant indicating that the current {@code ResultSet} object617* should not be closed when calling {@code getMoreResults}.618*619* @since 1.4620*/621int KEEP_CURRENT_RESULT = 2;622623/**624* The constant indicating that all {@code ResultSet} objects that625* have previously been kept open should be closed when calling626* {@code getMoreResults}.627*628* @since 1.4629*/630int CLOSE_ALL_RESULTS = 3;631632/**633* The constant indicating that a batch statement executed successfully634* but that no count of the number of rows it affected is available.635*636* @since 1.4637*/638int SUCCESS_NO_INFO = -2;639640/**641* The constant indicating that an error occurred while executing a642* batch statement.643*644* @since 1.4645*/646int EXECUTE_FAILED = -3;647648/**649* The constant indicating that generated keys should be made650* available for retrieval.651*652* @since 1.4653*/654int RETURN_GENERATED_KEYS = 1;655656/**657* The constant indicating that generated keys should not be made658* available for retrieval.659*660* @since 1.4661*/662int NO_GENERATED_KEYS = 2;663664/**665* Moves to this {@code Statement} object's next result, deals with666* any current {@code ResultSet} object(s) according to the instructions667* specified by the given flag, and returns668* {@code true} if the next result is a {@code ResultSet} object.669*670* <P>There are no more results when the following is true:671* <PRE>{@code672* // stmt is a Statement object673* ((stmt.getMoreResults(current) == false) && (stmt.getUpdateCount() == -1))674* }</PRE>675*676* @param current one of the following {@code Statement}677* constants indicating what should happen to current678* {@code ResultSet} objects obtained using the method679* {@code getResultSet}:680* {@code Statement.CLOSE_CURRENT_RESULT},681* {@code Statement.KEEP_CURRENT_RESULT}, or682* {@code Statement.CLOSE_ALL_RESULTS}683* @return {@code true} if the next result is a {@code ResultSet}684* object; {@code false} if it is an update count or there are no685* more results686* @throws SQLException if a database access error occurs,687* this method is called on a closed {@code Statement} or the argument688* supplied is not one of the following:689* {@code Statement.CLOSE_CURRENT_RESULT},690* {@code Statement.KEEP_CURRENT_RESULT} or691* {@code Statement.CLOSE_ALL_RESULTS}692*@throws SQLFeatureNotSupportedException if693* {@code DatabaseMetaData.supportsMultipleOpenResults} returns694* {@code false} and either695* {@code Statement.KEEP_CURRENT_RESULT} or696* {@code Statement.CLOSE_ALL_RESULTS} are supplied as697* the argument.698* @since 1.4699* @see #execute700*/701boolean getMoreResults(int current) throws SQLException;702703/**704* Retrieves any auto-generated keys created as a result of executing this705* {@code Statement} object. If this {@code Statement} object did706* not generate any keys, an empty {@code ResultSet}707* object is returned.708*709*<p><B>Note:</B>If the columns which represent the auto-generated keys were not specified,710* the JDBC driver implementation will determine the columns which best represent the auto-generated keys.711*712* @return a {@code ResultSet} object containing the auto-generated key(s)713* generated by the execution of this {@code Statement} object714* @throws SQLException if a database access error occurs or715* this method is called on a closed {@code Statement}716* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method717* @since 1.4718*/719ResultSet getGeneratedKeys() throws SQLException;720721/**722* Executes the given SQL statement and signals the driver with the723* given flag about whether the724* auto-generated keys produced by this {@code Statement} object725* should be made available for retrieval. The driver will ignore the726* flag if the SQL statement727* is not an {@code INSERT} statement, or an SQL statement able to return728* auto-generated keys (the list of such statements is vendor-specific).729*<p>730* <strong>Note:</strong>This method cannot be called on a731* {@code PreparedStatement} or {@code CallableStatement}.732* @param sql an SQL Data Manipulation Language (DML) statement, such as {@code INSERT}, {@code UPDATE} or733* {@code DELETE}; or an SQL statement that returns nothing,734* such as a DDL statement.735*736* @param autoGeneratedKeys a flag indicating whether auto-generated keys737* should be made available for retrieval;738* one of the following constants:739* {@code Statement.RETURN_GENERATED_KEYS}740* {@code Statement.NO_GENERATED_KEYS}741* @return either (1) the row count for SQL Data Manipulation Language (DML) statements742* or (2) 0 for SQL statements that return nothing743*744* @throws SQLException if a database access error occurs,745* this method is called on a closed {@code Statement}, the given746* SQL statement returns a {@code ResultSet} object,747* the given constant is not one of those allowed, the method is called on a748* {@code PreparedStatement} or {@code CallableStatement}749* @throws SQLFeatureNotSupportedException if the JDBC driver does not support750* this method with a constant of Statement.RETURN_GENERATED_KEYS751* @throws SQLTimeoutException when the driver has determined that the752* timeout value that was specified by the {@code setQueryTimeout}753* method has been exceeded and has at least attempted to cancel754* the currently running {@code Statement}755* @since 1.4756*/757int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException;758759/**760* Executes the given SQL statement and signals the driver that the761* auto-generated keys indicated in the given array should be made available762* for retrieval. This array contains the indexes of the columns in the763* target table that contain the auto-generated keys that should be made764* available. The driver will ignore the array if the SQL statement765* is not an {@code INSERT} statement, or an SQL statement able to return766* auto-generated keys (the list of such statements is vendor-specific).767*<p>768* <strong>Note:</strong>This method cannot be called on a769* {@code PreparedStatement} or {@code CallableStatement}.770* @param sql an SQL Data Manipulation Language (DML) statement, such as {@code INSERT}, {@code UPDATE} or771* {@code DELETE}; or an SQL statement that returns nothing,772* such as a DDL statement.773*774* @param columnIndexes an array of column indexes indicating the columns775* that should be returned from the inserted row776* @return either (1) the row count for SQL Data Manipulation Language (DML) statements777* or (2) 0 for SQL statements that return nothing778*779* @throws SQLException if a database access error occurs,780* this method is called on a closed {@code Statement}, the SQL781* statement returns a {@code ResultSet} object,the second argument782* supplied to this method is not an783* {@code int} array whose elements are valid column indexes, the method is called on a784* {@code PreparedStatement} or {@code CallableStatement}785* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method786* @throws SQLTimeoutException when the driver has determined that the787* timeout value that was specified by the {@code setQueryTimeout}788* method has been exceeded and has at least attempted to cancel789* the currently running {@code Statement}790* @since 1.4791*/792int executeUpdate(String sql, int columnIndexes[]) throws SQLException;793794/**795* Executes the given SQL statement and signals the driver that the796* auto-generated keys indicated in the given array should be made available797* for retrieval. This array contains the names of the columns in the798* target table that contain the auto-generated keys that should be made799* available. The driver will ignore the array if the SQL statement800* is not an {@code INSERT} statement, or an SQL statement able to return801* auto-generated keys (the list of such statements is vendor-specific).802*<p>803* <strong>Note:</strong>This method cannot be called on a804* {@code PreparedStatement} or {@code CallableStatement}.805* @param sql an SQL Data Manipulation Language (DML) statement, such as {@code INSERT}, {@code UPDATE} or806* {@code DELETE}; or an SQL statement that returns nothing,807* such as a DDL statement.808* @param columnNames an array of the names of the columns that should be809* returned from the inserted row810* @return either the row count for {@code INSERT}, {@code UPDATE},811* or {@code DELETE} statements, or 0 for SQL statements812* that return nothing813* @throws SQLException if a database access error occurs,814* this method is called on a closed {@code Statement}, the SQL815* statement returns a {@code ResultSet} object, the816* second argument supplied to this method is not a {@code String} array817* whose elements are valid column names, the method is called on a818* {@code PreparedStatement} or {@code CallableStatement}819* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method820* @throws SQLTimeoutException when the driver has determined that the821* timeout value that was specified by the {@code setQueryTimeout}822* method has been exceeded and has at least attempted to cancel823* the currently running {@code Statement}824* @since 1.4825*/826int executeUpdate(String sql, String columnNames[]) throws SQLException;827828/**829* Executes the given SQL statement, which may return multiple results,830* and signals the driver that any831* auto-generated keys should be made available832* for retrieval. The driver will ignore this signal if the SQL statement833* is not an {@code INSERT} statement, or an SQL statement able to return834* auto-generated keys (the list of such statements is vendor-specific).835* <P>836* In some (uncommon) situations, a single SQL statement may return837* multiple result sets and/or update counts. Normally you can ignore838* this unless you are (1) executing a stored procedure that you know may839* return multiple results or (2) you are dynamically executing an840* unknown SQL string.841* <P>842* The {@code execute} method executes an SQL statement and indicates the843* form of the first result. You must then use the methods844* {@code getResultSet} or {@code getUpdateCount}845* to retrieve the result, and {@code getMoreResults} to846* move to any subsequent result(s).847*<p>848*<strong>Note:</strong>This method cannot be called on a849* {@code PreparedStatement} or {@code CallableStatement}.850* @param sql any SQL statement851* @param autoGeneratedKeys a constant indicating whether auto-generated852* keys should be made available for retrieval using the method853* {@code getGeneratedKeys}; one of the following constants:854* {@code Statement.RETURN_GENERATED_KEYS} or855* {@code Statement.NO_GENERATED_KEYS}856* @return {@code true} if the first result is a {@code ResultSet}857* object; {@code false} if it is an update count or there are858* no results859* @throws SQLException if a database access error occurs,860* this method is called on a closed {@code Statement}, the second861* parameter supplied to this method is not862* {@code Statement.RETURN_GENERATED_KEYS} or863* {@code Statement.NO_GENERATED_KEYS},864* the method is called on a865* {@code PreparedStatement} or {@code CallableStatement}866* @throws SQLFeatureNotSupportedException if the JDBC driver does not support867* this method with a constant of Statement.RETURN_GENERATED_KEYS868* @throws SQLTimeoutException when the driver has determined that the869* timeout value that was specified by the {@code setQueryTimeout}870* method has been exceeded and has at least attempted to cancel871* the currently running {@code Statement}872* @see #getResultSet873* @see #getUpdateCount874* @see #getMoreResults875* @see #getGeneratedKeys876*877* @since 1.4878*/879boolean execute(String sql, int autoGeneratedKeys) throws SQLException;880881/**882* Executes the given SQL statement, which may return multiple results,883* and signals the driver that the884* auto-generated keys indicated in the given array should be made available885* for retrieval. This array contains the indexes of the columns in the886* target table that contain the auto-generated keys that should be made887* available. The driver will ignore the array if the SQL statement888* is not an {@code INSERT} statement, or an SQL statement able to return889* auto-generated keys (the list of such statements is vendor-specific).890* <P>891* Under some (uncommon) situations, a single SQL statement may return892* multiple result sets and/or update counts. Normally you can ignore893* this unless you are (1) executing a stored procedure that you know may894* return multiple results or (2) you are dynamically executing an895* unknown SQL string.896* <P>897* The {@code execute} method executes an SQL statement and indicates the898* form of the first result. You must then use the methods899* {@code getResultSet} or {@code getUpdateCount}900* to retrieve the result, and {@code getMoreResults} to901* move to any subsequent result(s).902*<p>903* <strong>Note:</strong>This method cannot be called on a904* {@code PreparedStatement} or {@code CallableStatement}.905* @param sql any SQL statement906* @param columnIndexes an array of the indexes of the columns in the907* inserted row that should be made available for retrieval by a908* call to the method {@code getGeneratedKeys}909* @return {@code true} if the first result is a {@code ResultSet}910* object; {@code false} if it is an update count or there911* are no results912* @throws SQLException if a database access error occurs,913* this method is called on a closed {@code Statement}, the914* elements in the {@code int} array passed to this method915* are not valid column indexes, the method is called on a916* {@code PreparedStatement} or {@code CallableStatement}917* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method918* @throws SQLTimeoutException when the driver has determined that the919* timeout value that was specified by the {@code setQueryTimeout}920* method has been exceeded and has at least attempted to cancel921* the currently running {@code Statement}922* @see #getResultSet923* @see #getUpdateCount924* @see #getMoreResults925*926* @since 1.4927*/928boolean execute(String sql, int columnIndexes[]) throws SQLException;929930/**931* Executes the given SQL statement, which may return multiple results,932* and signals the driver that the933* auto-generated keys indicated in the given array should be made available934* for retrieval. This array contains the names of the columns in the935* target table that contain the auto-generated keys that should be made936* available. The driver will ignore the array if the SQL statement937* is not an {@code INSERT} statement, or an SQL statement able to return938* auto-generated keys (the list of such statements is vendor-specific).939* <P>940* In some (uncommon) situations, a single SQL statement may return941* multiple result sets and/or update counts. Normally you can ignore942* this unless you are (1) executing a stored procedure that you know may943* return multiple results or (2) you are dynamically executing an944* unknown SQL string.945* <P>946* The {@code execute} method executes an SQL statement and indicates the947* form of the first result. You must then use the methods948* {@code getResultSet} or {@code getUpdateCount}949* to retrieve the result, and {@code getMoreResults} to950* move to any subsequent result(s).951*<p>952* <strong>Note:</strong>This method cannot be called on a953* {@code PreparedStatement} or {@code CallableStatement}.954* @param sql any SQL statement955* @param columnNames an array of the names of the columns in the inserted956* row that should be made available for retrieval by a call to the957* method {@code getGeneratedKeys}958* @return {@code true} if the next result is a {@code ResultSet}959* object; {@code false} if it is an update count or there960* are no more results961* @throws SQLException if a database access error occurs,962* this method is called on a closed {@code Statement},the963* elements of the {@code String} array passed to this964* method are not valid column names, the method is called on a965* {@code PreparedStatement} or {@code CallableStatement}966* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method967* @throws SQLTimeoutException when the driver has determined that the968* timeout value that was specified by the {@code setQueryTimeout}969* method has been exceeded and has at least attempted to cancel970* the currently running {@code Statement}971* @see #getResultSet972* @see #getUpdateCount973* @see #getMoreResults974* @see #getGeneratedKeys975*976* @since 1.4977*/978boolean execute(String sql, String columnNames[]) throws SQLException;979980/**981* Retrieves the result set holdability for {@code ResultSet} objects982* generated by this {@code Statement} object.983*984* @return either {@code ResultSet.HOLD_CURSORS_OVER_COMMIT} or985* {@code ResultSet.CLOSE_CURSORS_AT_COMMIT}986* @throws SQLException if a database access error occurs or987* this method is called on a closed {@code Statement}988*989* @since 1.4990*/991int getResultSetHoldability() throws SQLException;992993/**994* Retrieves whether this {@code Statement} object has been closed. A {@code Statement} is closed if the995* method close has been called on it, or if it is automatically closed.996* @return true if this {@code Statement} object is closed; false if it is still open997* @throws SQLException if a database access error occurs998* @since 1.6999*/1000boolean isClosed() throws SQLException;10011002/**1003* Requests that a {@code Statement} be pooled or not pooled. The value1004* specified is a hint to the statement pool implementation indicating1005* whether the application wants the statement to be pooled. It is up to1006* the statement pool manager as to whether the hint is used.1007* <p>1008* The poolable value of a statement is applicable to both internal1009* statement caches implemented by the driver and external statement caches1010* implemented by application servers and other applications.1011* <p>1012* By default, a {@code Statement} is not poolable when created, and1013* a {@code PreparedStatement} and {@code CallableStatement}1014* are poolable when created.1015*1016* @param poolable requests that the statement be pooled if true and1017* that the statement not be pooled if false1018*1019* @throws SQLException if this method is called on a closed1020* {@code Statement}1021*1022* @since 1.61023*/1024void setPoolable(boolean poolable)1025throws SQLException;10261027/**1028* Returns a value indicating whether the {@code Statement}1029* is poolable or not.1030*1031* @return {@code true} if the {@code Statement}1032* is poolable; {@code false} otherwise1033*1034* @throws SQLException if this method is called on a closed1035* {@code Statement}1036*1037* @since 1.61038*1039* @see java.sql.Statement#setPoolable(boolean) setPoolable(boolean)1040*/1041boolean isPoolable()1042throws SQLException;10431044//--------------------------JDBC 4.1 -----------------------------10451046/**1047* Specifies that this {@code Statement} will be closed when all its1048* dependent result sets are closed. If execution of the {@code Statement}1049* does not produce any result sets, this method has no effect.1050* <p>1051* <strong>Note:</strong> Multiple calls to {@code closeOnCompletion} do1052* not toggle the effect on this {@code Statement}. However, a call to1053* {@code closeOnCompletion} does effect both the subsequent execution of1054* statements, and statements that currently have open, dependent,1055* result sets.1056*1057* @throws SQLException if this method is called on a closed1058* {@code Statement}1059* @since 1.71060*/1061public void closeOnCompletion() throws SQLException;10621063/**1064* Returns a value indicating whether this {@code Statement} will be1065* closed when all its dependent result sets are closed.1066* @return {@code true} if the {@code Statement} will be closed when all1067* of its dependent result sets are closed; {@code false} otherwise1068* @throws SQLException if this method is called on a closed1069* {@code Statement}1070* @since 1.71071*/1072public boolean isCloseOnCompletion() throws SQLException;107310741075//--------------------------JDBC 4.2 -----------------------------10761077/**1078* Retrieves the current result as an update count; if the result1079* is a {@code ResultSet} object or there are no more results, -11080* is returned. This method should be called only once per result.1081* <p>1082* This method should be used when the returned row count may exceed1083* {@link Integer#MAX_VALUE}.1084*<p>1085* The default implementation will throw {@code UnsupportedOperationException}1086*1087* @return the current result as an update count; -1 if the current result1088* is a {@code ResultSet} object or there are no more results1089* @throws SQLException if a database access error occurs or1090* this method is called on a closed {@code Statement}1091* @see #execute1092* @since 1.81093*/1094default long getLargeUpdateCount() throws SQLException {1095throw new UnsupportedOperationException("getLargeUpdateCount not implemented");1096}10971098/**1099* Sets the limit for the maximum number of rows that any1100* {@code ResultSet} object generated by this {@code Statement}1101* object can contain to the given number.1102* If the limit is exceeded, the excess1103* rows are silently dropped.1104* <p>1105* This method should be used when the row limit may exceed1106* {@link Integer#MAX_VALUE}.1107*<p>1108* The default implementation will throw {@code UnsupportedOperationException}1109*1110* @param max the new max rows limit; zero means there is no limit1111* @throws SQLException if a database access error occurs,1112* this method is called on a closed {@code Statement}1113* or the condition {@code max >= 0} is not satisfied1114* @see #getMaxRows1115* @since 1.81116*/1117default void setLargeMaxRows(long max) throws SQLException {1118throw new UnsupportedOperationException("setLargeMaxRows not implemented");1119}11201121/**1122* Retrieves the maximum number of rows that a1123* {@code ResultSet} object produced by this1124* {@code Statement} object can contain. If this limit is exceeded,1125* the excess rows are silently dropped.1126* <p>1127* This method should be used when the returned row limit may exceed1128* {@link Integer#MAX_VALUE}.1129*<p>1130* The default implementation will return {@code 0}1131*1132* @return the current maximum number of rows for a {@code ResultSet}1133* object produced by this {@code Statement} object;1134* zero means there is no limit1135* @throws SQLException if a database access error occurs or1136* this method is called on a closed {@code Statement}1137* @see #setMaxRows1138* @since 1.81139*/1140default long getLargeMaxRows() throws SQLException {1141return 0;1142}11431144/**1145* Submits a batch of commands to the database for execution and1146* if all commands execute successfully, returns an array of update counts.1147* The {@code long} elements of the array that is returned are ordered1148* to correspond to the commands in the batch, which are ordered1149* according to the order in which they were added to the batch.1150* The elements in the array returned by the method {@code executeLargeBatch}1151* may be one of the following:1152* <OL>1153* <LI>A number greater than or equal to zero -- indicates that the1154* command was processed successfully and is an update count giving the1155* number of rows in the database that were affected by the command's1156* execution1157* <LI>A value of {@code SUCCESS_NO_INFO} -- indicates that the command was1158* processed successfully but that the number of rows affected is1159* unknown1160* <P>1161* If one of the commands in a batch update fails to execute properly,1162* this method throws a {@code BatchUpdateException}, and a JDBC1163* driver may or may not continue to process the remaining commands in1164* the batch. However, the driver's behavior must be consistent with a1165* particular DBMS, either always continuing to process commands or never1166* continuing to process commands. If the driver continues processing1167* after a failure, the array returned by the method1168* {@code BatchUpdateException.getLargeUpdateCounts}1169* will contain as many elements as there are commands in the batch, and1170* at least one of the elements will be the following:1171*1172* <LI>A value of {@code EXECUTE_FAILED} -- indicates that the command failed1173* to execute successfully and occurs only if a driver continues to1174* process commands after a command fails1175* </OL>1176* <p>1177* This method should be used when the returned row count may exceed1178* {@link Integer#MAX_VALUE}.1179*<p>1180* The default implementation will throw {@code UnsupportedOperationException}1181*1182* @return an array of update counts containing one element for each1183* command in the batch. The elements of the array are ordered according1184* to the order in which commands were added to the batch.1185* @throws SQLException if a database access error occurs,1186* this method is called on a closed {@code Statement} or the1187* driver does not support batch statements. Throws {@link BatchUpdateException}1188* (a subclass of {@code SQLException}) if one of the commands sent to the1189* database fails to execute properly or attempts to return a result set.1190* @throws SQLTimeoutException when the driver has determined that the1191* timeout value that was specified by the {@code setQueryTimeout}1192* method has been exceeded and has at least attempted to cancel1193* the currently running {@code Statement}1194*1195* @see #addBatch1196* @see DatabaseMetaData#supportsBatchUpdates1197* @since 1.81198*/1199default long[] executeLargeBatch() throws SQLException {1200throw new UnsupportedOperationException("executeLargeBatch not implemented");1201}12021203/**1204* Executes the given SQL statement, which may be an {@code INSERT},1205* {@code UPDATE}, or {@code DELETE} statement or an1206* SQL statement that returns nothing, such as an SQL DDL statement.1207* <p>1208* This method should be used when the returned row count may exceed1209* {@link Integer#MAX_VALUE}.1210* <p>1211* <strong>Note:</strong>This method cannot be called on a1212* {@code PreparedStatement} or {@code CallableStatement}.1213*<p>1214* The default implementation will throw {@code UnsupportedOperationException}1215*1216* @param sql an SQL Data Manipulation Language (DML) statement,1217* such as {@code INSERT}, {@code UPDATE} or1218* {@code DELETE}; or an SQL statement that returns nothing,1219* such as a DDL statement.1220*1221* @return either (1) the row count for SQL Data Manipulation Language1222* (DML) statements or (2) 0 for SQL statements that return nothing1223*1224* @throws SQLException if a database access error occurs,1225* this method is called on a closed {@code Statement}, the given1226* SQL statement produces a {@code ResultSet} object, the method is called on a1227* {@code PreparedStatement} or {@code CallableStatement}1228* @throws SQLTimeoutException when the driver has determined that the1229* timeout value that was specified by the {@code setQueryTimeout}1230* method has been exceeded and has at least attempted to cancel1231* the currently running {@code Statement}1232* @since 1.81233*/1234default long executeLargeUpdate(String sql) throws SQLException {1235throw new UnsupportedOperationException("executeLargeUpdate not implemented");1236}12371238/**1239* Executes the given SQL statement and signals the driver with the1240* given flag about whether the1241* auto-generated keys produced by this {@code Statement} object1242* should be made available for retrieval. The driver will ignore the1243* flag if the SQL statement1244* is not an {@code INSERT} statement, or an SQL statement able to return1245* auto-generated keys (the list of such statements is vendor-specific).1246* <p>1247* This method should be used when the returned row count may exceed1248* {@link Integer#MAX_VALUE}.1249* <p>1250* <strong>Note:</strong>This method cannot be called on a1251* {@code PreparedStatement} or {@code CallableStatement}.1252*<p>1253* The default implementation will throw {@code SQLFeatureNotSupportedException}1254*1255* @param sql an SQL Data Manipulation Language (DML) statement,1256* such as {@code INSERT}, {@code UPDATE} or1257* {@code DELETE}; or an SQL statement that returns nothing,1258* such as a DDL statement.1259*1260* @param autoGeneratedKeys a flag indicating whether auto-generated keys1261* should be made available for retrieval;1262* one of the following constants:1263* {@code Statement.RETURN_GENERATED_KEYS}1264* {@code Statement.NO_GENERATED_KEYS}1265* @return either (1) the row count for SQL Data Manipulation Language (DML) statements1266* or (2) 0 for SQL statements that return nothing1267*1268* @throws SQLException if a database access error occurs,1269* this method is called on a closed {@code Statement}, the given1270* SQL statement returns a {@code ResultSet} object,1271* the given constant is not one of those allowed, the method is called on a1272* {@code PreparedStatement} or {@code CallableStatement}1273* @throws SQLFeatureNotSupportedException if the JDBC driver does not support1274* this method with a constant of Statement.RETURN_GENERATED_KEYS1275* @throws SQLTimeoutException when the driver has determined that the1276* timeout value that was specified by the {@code setQueryTimeout}1277* method has been exceeded and has at least attempted to cancel1278* the currently running {@code Statement}1279* @since 1.81280*/1281default long executeLargeUpdate(String sql, int autoGeneratedKeys)1282throws SQLException {1283throw new SQLFeatureNotSupportedException("executeLargeUpdate not implemented");1284}12851286/**1287* Executes the given SQL statement and signals the driver that the1288* auto-generated keys indicated in the given array should be made available1289* for retrieval. This array contains the indexes of the columns in the1290* target table that contain the auto-generated keys that should be made1291* available. The driver will ignore the array if the SQL statement1292* is not an {@code INSERT} statement, or an SQL statement able to return1293* auto-generated keys (the list of such statements is vendor-specific).1294* <p>1295* This method should be used when the returned row count may exceed1296* {@link Integer#MAX_VALUE}.1297* <p>1298* <strong>Note:</strong>This method cannot be called on a1299* {@code PreparedStatement} or {@code CallableStatement}.1300*<p>1301* The default implementation will throw {@code SQLFeatureNotSupportedException}1302*1303* @param sql an SQL Data Manipulation Language (DML) statement,1304* such as {@code INSERT}, {@code UPDATE} or1305* {@code DELETE}; or an SQL statement that returns nothing,1306* such as a DDL statement.1307*1308* @param columnIndexes an array of column indexes indicating the columns1309* that should be returned from the inserted row1310* @return either (1) the row count for SQL Data Manipulation Language (DML) statements1311* or (2) 0 for SQL statements that return nothing1312*1313* @throws SQLException if a database access error occurs,1314* this method is called on a closed {@code Statement}, the SQL1315* statement returns a {@code ResultSet} object,the second argument1316* supplied to this method is not an1317* {@code int} array whose elements are valid column indexes, the method is called on a1318* {@code PreparedStatement} or {@code CallableStatement}1319* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method1320* @throws SQLTimeoutException when the driver has determined that the1321* timeout value that was specified by the {@code setQueryTimeout}1322* method has been exceeded and has at least attempted to cancel1323* the currently running {@code Statement}1324* @since 1.81325*/1326default long executeLargeUpdate(String sql, int columnIndexes[]) throws SQLException {1327throw new SQLFeatureNotSupportedException("executeLargeUpdate not implemented");1328}13291330/**1331* Executes the given SQL statement and signals the driver that the1332* auto-generated keys indicated in the given array should be made available1333* for retrieval. This array contains the names of the columns in the1334* target table that contain the auto-generated keys that should be made1335* available. The driver will ignore the array if the SQL statement1336* is not an {@code INSERT} statement, or an SQL statement able to return1337* auto-generated keys (the list of such statements is vendor-specific).1338* <p>1339* This method should be used when the returned row count may exceed1340* {@link Integer#MAX_VALUE}.1341* <p>1342* <strong>Note:</strong>This method cannot be called on a1343* {@code PreparedStatement} or {@code CallableStatement}.1344*<p>1345* The default implementation will throw {@code SQLFeatureNotSupportedException}1346*1347* @param sql an SQL Data Manipulation Language (DML) statement,1348* such as {@code INSERT}, {@code UPDATE} or1349* {@code DELETE}; or an SQL statement that returns nothing,1350* such as a DDL statement.1351* @param columnNames an array of the names of the columns that should be1352* returned from the inserted row1353* @return either the row count for {@code INSERT}, {@code UPDATE},1354* or {@code DELETE} statements, or 0 for SQL statements1355* that return nothing1356* @throws SQLException if a database access error occurs,1357* this method is called on a closed {@code Statement}, the SQL1358* statement returns a {@code ResultSet} object, the1359* second argument supplied to this method is not a {@code String} array1360* whose elements are valid column names, the method is called on a1361* {@code PreparedStatement} or {@code CallableStatement}1362* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method1363* @throws SQLTimeoutException when the driver has determined that the1364* timeout value that was specified by the {@code setQueryTimeout}1365* method has been exceeded and has at least attempted to cancel1366* the currently running {@code Statement}1367* @since 1.81368*/1369default long executeLargeUpdate(String sql, String columnNames[])1370throws SQLException {1371throw new SQLFeatureNotSupportedException("executeLargeUpdate not implemented");1372}13731374// JDBC 4.313751376/**1377* Returns a {@code String} enclosed in single quotes. Any occurrence of a1378* single quote within the string will be replaced by two single quotes.1379*1380* <blockquote>1381* <table class="striped">1382* <caption>Examples of the conversion:</caption>1383* <thead>1384* <tr><th scope="col">Value</th><th scope="col">Result</th></tr>1385* </thead>1386* <tbody style="text-align:center">1387* <tr> <th scope="row">Hello</th> <td>'Hello'</td> </tr>1388* <tr> <th scope="row">G'Day</th> <td>'G''Day'</td> </tr>1389* <tr> <th scope="row">'G''Day'</th>1390* <td>'''G''''Day'''</td> </tr>1391* <tr> <th scope="row">I'''M</th> <td>'I''''''M'</td>1392* </tr>1393*1394* </tbody>1395* </table>1396* </blockquote>1397* @implNote1398* JDBC driver implementations may need to provide their own implementation1399* of this method in order to meet the requirements of the underlying1400* datasource.1401* @param val a character string1402* @return A string enclosed by single quotes with every single quote1403* converted to two single quotes1404* @throws NullPointerException if val is {@code null}1405* @throws SQLException if a database access error occurs1406*1407* @since 91408*/1409default String enquoteLiteral(String val) throws SQLException {1410return "'" + val.replace("'", "''") + "'";1411}141214131414/**1415* Returns a SQL identifier. If {@code identifier} is a simple SQL identifier:1416* <ul>1417* <li>Return the original value if {@code alwaysQuote} is1418* {@code false}</li>1419* <li>Return a delimited identifier if {@code alwaysQuote} is1420* {@code true}</li>1421* </ul>1422*1423* If {@code identifier} is not a simple SQL identifier, {@code identifier} will be1424* enclosed in double quotes if not already present. If the datasource does1425* not support double quotes for delimited identifiers, the1426* identifier should be enclosed by the string returned from1427* {@link DatabaseMetaData#getIdentifierQuoteString}. If the datasource1428* does not support delimited identifiers, a1429* {@code SQLFeatureNotSupportedException} should be thrown.1430* <p>1431* A {@code SQLException} will be thrown if {@code identifier} contains any1432* characters invalid in a delimited identifier or the identifier length is1433* invalid for the datasource.1434*1435* @implSpec1436* The default implementation uses the following criteria to1437* determine a valid simple SQL identifier:1438* <ul>1439* <li>The string is not enclosed in double quotes</li>1440* <li>The first character is an alphabetic character from a through z, or1441* from A through Z</li>1442* <li>The name only contains alphanumeric characters or the character "_"</li>1443* </ul>1444*1445* The default implementation will throw a {@code SQLException} if:1446* <ul>1447* <li>{@code identifier} contains a {@code null} character or double quote and is not1448* a simple SQL identifier.</li>1449* <li>The length of {@code identifier} is less than 1 or greater than 128 characters1450* </ul>1451* <blockquote>1452* <table class="striped" >1453* <caption>Examples of the conversion:</caption>1454* <thead>1455* <tr>1456* <th scope="col">identifier</th>1457* <th scope="col">alwaysQuote</th>1458* <th scope="col">Result</th></tr>1459* </thead>1460* <tbody>1461* <tr>1462* <th scope="row">Hello</th>1463* <td>false</td>1464* <td>Hello</td>1465* </tr>1466* <tr>1467* <th scope="row">Hello</th>1468* <td>true</td>1469* <td>"Hello"</td>1470* </tr>1471* <tr>1472* <th scope="row">G'Day</th>1473* <td>false</td>1474* <td>"G'Day"</td>1475* </tr>1476* <tr>1477* <th scope="row">"Bruce Wayne"</th>1478* <td>false</td>1479* <td>"Bruce Wayne"</td>1480* </tr>1481* <tr>1482* <th scope="row">"Bruce Wayne"</th>1483* <td>true</td>1484* <td>"Bruce Wayne"</td>1485* </tr>1486* <tr>1487* <th scope="row">GoodDay$</th>1488* <td>false</td>1489* <td>"GoodDay$"</td>1490* </tr>1491* <tr>1492* <th scope="row">Hello"World</th>1493* <td>false</td>1494* <td>SQLException</td>1495* </tr>1496* <tr>1497* <th scope="row">"Hello"World"</th>1498* <td>false</td>1499* <td>SQLException</td>1500* </tr>1501* </tbody>1502* </table>1503* </blockquote>1504* @implNote1505* JDBC driver implementations may need to provide their own implementation1506* of this method in order to meet the requirements of the underlying1507* datasource.1508* @param identifier a SQL identifier1509* @param alwaysQuote indicates if a simple SQL identifier should be1510* returned as a quoted identifier1511* @return A simple SQL identifier or a delimited identifier1512* @throws SQLException if identifier is not a valid identifier1513* @throws SQLFeatureNotSupportedException if the datasource does not support1514* delimited identifiers1515* @throws NullPointerException if identifier is {@code null}1516*1517* @since 91518*/1519default String enquoteIdentifier(String identifier, boolean alwaysQuote) throws SQLException {1520int len = identifier.length();1521if (len < 1 || len > 128) {1522throw new SQLException("Invalid name");1523}1524if (Pattern.compile("[\\p{Alpha}][\\p{Alnum}_]*").matcher(identifier).matches()) {1525return alwaysQuote ? "\"" + identifier + "\"" : identifier;1526}1527if (identifier.matches("^\".+\"$")) {1528identifier = identifier.substring(1, len - 1);1529}1530if (Pattern.compile("[^\u0000\"]+").matcher(identifier).matches()) {1531return "\"" + identifier + "\"";1532} else {1533throw new SQLException("Invalid name");1534}1535}15361537/**1538* Retrieves whether {@code identifier} is a simple SQL identifier.1539*1540* @implSpec The default implementation uses the following criteria to1541* determine a valid simple SQL identifier:1542* <ul>1543* <li>The string is not enclosed in double quotes</li>1544* <li>The first character is an alphabetic character from a through z, or1545* from A through Z</li>1546* <li>The string only contains alphanumeric characters or the character1547* "_"</li>1548* <li>The string is between 1 and 128 characters in length inclusive</li>1549* </ul>1550*1551* <blockquote>1552* <table class="striped" >1553* <caption>Examples of the conversion:</caption>1554* <thead>1555* <tr>1556* <th scope="col">identifier</th>1557* <th scope="col">Simple Identifier</th>1558* </thead>1559*1560* <tbody>1561* <tr>1562* <th scope="row">Hello</th>1563* <td>true</td>1564* </tr>1565* <tr>1566* <th scope="row">G'Day</th>1567* <td>false</td>1568* </tr>1569* <tr>1570* <th scope="row">"Bruce Wayne"</th>1571* <td>false</td>1572* </tr>1573* <tr>1574* <th scope="row">GoodDay$</th>1575* <td>false</td>1576* </tr>1577* <tr>1578* <th scope="row">Hello"World</th>1579* <td>false</td>1580* </tr>1581* <tr>1582* <th scope="row">"Hello"World"</th>1583* <td>false</td>1584* </tr>1585* </tbody>1586* </table>1587* </blockquote>1588* @implNote JDBC driver implementations may need to provide their own1589* implementation of this method in order to meet the requirements of the1590* underlying datasource.1591* @param identifier a SQL identifier1592* @return true if a simple SQL identifier, false otherwise1593* @throws NullPointerException if identifier is {@code null}1594* @throws SQLException if a database access error occurs1595*1596* @since 91597*/1598default boolean isSimpleIdentifier(String identifier) throws SQLException {1599int len = identifier.length();1600return len >= 1 && len <= 1281601&& Pattern.compile("[\\p{Alpha}][\\p{Alnum}_]*").matcher(identifier).matches();1602}16031604/**1605* Returns a {@code String} representing a National Character Set Literal1606* enclosed in single quotes and prefixed with a upper case letter N.1607* Any occurrence of a single quote within the string will be replaced1608* by two single quotes.1609*1610* <blockquote>1611* <table class="striped">1612* <caption>Examples of the conversion:</caption>1613* <thead>1614* <tr>1615* <th scope="col">Value</th>1616* <th scope="col">Result</th>1617* </tr>1618* </thead>1619* <tbody>1620* <tr> <th scope="row">Hello</th> <td>N'Hello'</td> </tr>1621* <tr> <th scope="row">G'Day</th> <td>N'G''Day'</td> </tr>1622* <tr> <th scope="row">'G''Day'</th>1623* <td>N'''G''''Day'''</td> </tr>1624* <tr> <th scope="row">I'''M</th> <td>N'I''''''M'</td>1625* <tr> <th scope="row">N'Hello'</th> <td>N'N''Hello'''</td> </tr>1626*1627* </tbody>1628* </table>1629* </blockquote>1630* @implNote1631* JDBC driver implementations may need to provide their own implementation1632* of this method in order to meet the requirements of the underlying1633* datasource. An implementation of enquoteNCharLiteral may accept a different1634* set of characters than that accepted by the same drivers implementation of1635* enquoteLiteral.1636* @param val a character string1637* @return the result of replacing every single quote character in the1638* argument by two single quote characters where this entire result is1639* then prefixed with 'N'.1640* @throws NullPointerException if val is {@code null}1641* @throws SQLException if a database access error occurs1642*1643* @since 91644*/1645default String enquoteNCharLiteral(String val) throws SQLException {1646return "N'" + val.replace("'", "''") + "'";1647}1648}164916501651