Executes the given SQL statement, which may return multiple results,
and signals the driver that the
auto-generated keys indicated in the given array should be made available
for retrieval. This array contains the indexes of the columns in the
target table that contain the auto-generated keys that should be made
available. The driver will ignore the array if the SQL statement
is not an INSERT
statement, or an SQL statement able to return
auto-generated keys (the list of such statements is vendor-specific).
Under some (uncommon) situations, a single SQL statement may return multiple result sets and/or update counts. Normally you can ignore this unless you are (1) executing a stored procedure that you know may return multiple results or (2) you are dynamically executing an unknown SQL string.
The execute
method executes an SQL statement and indicates the
form of the first result. You must then use the methods
getResultSet
or getUpdateCount
to retrieve the result, and getMoreResults
to
move to any subsequent result(s).
Note:This method cannot be called on a
PreparedStatement
or CallableStatement
.
sql | any SQL statement | |
columnIndexes | an array of the indexes of the columns in the
inserted row that should be made available for retrieval by a
call to the method getGeneratedKeys |
true
if the first result is a ResultSet
object; false
if it is an update count or there
are no results
SQLException | if a database access error occurs,
this method is called on a closed Statement , the
elements in the int array passed to this method
are not valid column indexes, the method is called on a
PreparedStatement or CallableStatement | |
SQLFeatureNotSupportedException | if the JDBC driver does not support this method | |
SQLTimeoutException | when the driver has determined that the
timeout value that was specified by the setQueryTimeout
method has been exceeded and has at least attempted to cancel
the currently running Statement |
getResultSet, getUpdateCount, getMoreResults
Diagram: Statement