| java.sql.Statement |
Known Indirect Subclasses
|
Interface used for executing static SQL statements and returning their results. By default, an object implementing the Statement interface can returns results as ResultSets. For any given Statement object, only one ResultSet can be open at one time. A call to any of the execution methods of Statement will cause any previously created ResultSet object for that Statement to be closed implicitly.
To have multiple ResultSet objects open concurrently, multiple Statement objects must be used.
| Constants | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| int | CLOSE_ALL_RESULTS | Passing this constant to getMoreResults implies that all ResultSet objects previously kept open should be closed. | |||||||||
| int | CLOSE_CURRENT_RESULT | Passing this constant to getMoreResults implies that the current ResultSet object should be closed | |||||||||
| int | EXECUTE_FAILED | Indicates that an error was encountered during execution of a batch statement. | |||||||||
| int | KEEP_CURRENT_RESULT | Passing this constant to getMoreResults implies that the current ResultSet object should not be closed. | |||||||||
| int | NO_GENERATED_KEYS | Indicates that generated keys should not be accessible for retrieval. | |||||||||
| int | RETURN_GENERATED_KEYS | Indicates that generated keys should be accessible for retrieval. | |||||||||
| int | SUCCESS_NO_INFO | Indicates that a batch statement was executed with a successful result, but a count of the number of rows it affected is unavailable. | |||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Adds a specified SQL commands to the list of commands for this Statement.
| |||||||||||
Cancels this Statement execution if both the database and the JDBC driver
support aborting an SQL statement in flight.
| |||||||||||
Clears the current list of SQL commands for this Statement.
| |||||||||||
Clears all SQLWarnings from this Statement.
| |||||||||||
Releases this Statement's database and JDBC driver resources.
| |||||||||||
Executes the supplied SQL statement.
| |||||||||||
Executes a supplied SQL statement.
| |||||||||||
Executes a supplied SQL statement.
| |||||||||||
Executes the supplied SQL statement.
| |||||||||||
Submits a batch of SQL commands to the database.
| |||||||||||
Executes a supplied SQL statement.
| |||||||||||
Executes the supplied SQL statement.
| |||||||||||
Executes the supplied SQL statement.
| |||||||||||
Executes the supplied SQL statement.
| |||||||||||
Executes the supplied SQL statement.
| |||||||||||
Gets the Connection that produced this Statement.
| |||||||||||
Gets the default direction for fetching rows for ResultSets generated
from this Statement.
| |||||||||||
Gets the default number of rows for a fetch for the ResultSet objects
returned from this Statement.
| |||||||||||
Returns auto generated keys created by executing this Statement.
| |||||||||||
Gets the maximum number of bytes which can be returned for values from
Character and Binary values in a ResultSet derived from this Statement.
| |||||||||||
Gets the maximum number of rows that a ResultSet can contain when
produced from this Statement.
| |||||||||||
Moves to this Statement's next result.
| |||||||||||
Moves to this Statement's next result.
| |||||||||||
Gets the timeout value for Statement execution.
| |||||||||||
Gets the current result.
| |||||||||||
Gets the concurrency setting for ResultSet objects generated by this
Statement.
| |||||||||||
Gets the cursor hold setting for ResultSet objects generated by this
Statement.
| |||||||||||
Gets the ResultSet type setting for ResultSets derived from this
Statement.
| |||||||||||
Gets an update count for the current result if it is not a ResultSet.
| |||||||||||
Retrieves the first SQLWarning reported by calls on this Statement.
| |||||||||||
Sets the SQL cursor name.
| |||||||||||
Sets Escape Processing mode.
| |||||||||||
Sets the fetch direction - a hint to the JDBC driver about the direction
of processing of rows in ResultSets created by this Statement.
| |||||||||||
Sets the fetch size.
| |||||||||||
Sets the maximum number of bytes for ResultSet columns that contain
character or binary values.
| |||||||||||
Sets the maximum number of rows that any ResultSet can contain.
| |||||||||||
Sets the timeout, in seconds, for queries - how long the driver will
allow for completion of a Statement execution.
| |||||||||||
Passing this constant to getMoreResults implies that all ResultSet objects previously kept open should be closed.
Passing this constant to getMoreResults implies that the current ResultSet object should be closed
Indicates that an error was encountered during execution of a batch statement.
Passing this constant to getMoreResults implies that the current ResultSet object should not be closed.
Indicates that generated keys should not be accessible for retrieval.
Indicates that generated keys should be accessible for retrieval.
Indicates that a batch statement was executed with a successful result, but a count of the number of rows it affected is unavailable.
Adds a specified SQL commands to the list of commands for this Statement.
The list of commands is executed by invoking the
executeBatch method.
| sql | the SQL command as a String. Typically an INSERT or UPDATE statement. |
|---|
| SQLException | if an error occurs accessing the database or the database does not support batch updates |
|---|
Cancels this Statement execution if both the database and the JDBC driver support aborting an SQL statement in flight. This method can be used by one thread to stop a Statement that is being executed on another thread.
| SQLException | if an error occurs accessing the database |
|---|
Clears the current list of SQL commands for this Statement.
| SQLException | if an error occurs accessing the database or the database does not support batch updates |
|---|
Clears all SQLWarnings from this Statement.
| SQLException | if an error occurs accessing the database |
|---|
Releases this Statement's database and JDBC driver resources.
Using this method to release these resources as soon as possible is strongly recommended. It is not a good idea to rely on these resources being released when the Statement object is finalized during garbage collection. Doing so can result in unpredictable performance characteristics for the application.
| SQLException | if an error occurs accessing the database |
|---|
Executes the supplied SQL statement. This may return multiple ResultSets. This method allows retrieval of auto generated keys specified by the supplied array of column indexes, if the SQL statement is an INSERT statement.
Use the getResultSet or getUpdateCount
methods to get the first result and getMoreResults to get
any subsequent results.
| sql | the SQL statement to execute |
|---|---|
| columnNames | an array of column names in the inserted row which should be
made available for retrieval via the
getGeneratedKeys method. |
| SQLException | if an error occurs accessing the database |
|---|
Executes a supplied SQL statement. This may return multiple ResultSets.
Use the getResultSet or getUpdateCount
methods to get the first result and getMoreResults to get
any subsequent results.
| sql | the SQL statement to execute |
|---|
| SQLException | if an error occurs accessing the database |
|---|
Executes a supplied SQL statement. This may return multiple ResultSets. This method allows control of whether auto-generated Keys should be made available for retrieval, if the SQL statement is an INSERT statement.
Use the getResultSet or getUpdateCount
methods to get the first result and getMoreResults to get
any subsequent results.
| sql | the SQL statement to execute |
|---|---|
| autoGeneratedKeys | a flag indicating whether to make auto generated keys available for retrieval. This parameter must be one of Statement.NO_GENERATED_KEYS or Statement.RETURN_GENERATED_KEYS |
| SQLException | if an error occurs accessing the database |
|---|
Executes the supplied SQL statement. This may return multiple ResultSets. This method allows retrieval of auto generated keys specified by the supplied array of column indexes, if the SQL statement is an INSERT statement.
Use the getResultSet or getUpdateCount
methods to get the first result and getMoreResults to get
any subsequent results.
| sql | the SQL statement to execute |
|---|---|
| columnIndexes | an array of indexes of the columns in the inserted row which
should be made available for retrieval via the
getGeneratedKeys method. |
| SQLException | if an error occurs accessing the database |
|---|
Submits a batch of SQL commands to the database. Returns an array of update counts, if all the commands execute successfully.
If one of the commands in the batch fails, this method can throw a BatchUpdateException and the JDBC driver may or may not process the remaining commands. The JDBC driver must behave consistently with the underlying database, either always continuing or never continuing. If the driver continues processing, the array of results returned contains the same number of elements as there are commands in the batch, with a minimum of one of the elements having the EXECUTE_FAILED value.
| SQLException | if an error occurs accessing the database |
|---|
Executes a supplied SQL statement. Returns a single ResultSet.
| sql | an SQL statement to execute. Typically a SELECT statement |
|---|
| SQLException | if an error occurs accessing the database or if the statement produces anything other than a single ResultSet |
|---|
Executes the supplied SQL statement. This method allows retrieval of auto generated keys specified by the supplied array of column indexes.
| sql | an SQL statement to execute - an SQL INSERT, UPDATE, DELETE or a statement which returns nothing |
|---|---|
| columnIndexes | an array of indexes of the columns in the inserted row which
should be made available for retrieval via the
getGeneratedKeys method. |
| SQLException | if an error occurs accessing the database or if the statement produces a ResultSet |
|---|
Executes the supplied SQL statement. The statement may be an INSERT, UPDATE or DELETE statement or a statement which returns nothing.
| sql | an SQL statement to execute - an SQL INSERT, UPDATE, DELETE or a statement which returns nothing |
|---|
| SQLException | if an error occurs accessing the database or if the statement produces a ResultSet |
|---|
Executes the supplied SQL statement. This method allows retrieval of auto generated keys specified by the supplied array of column names.
| sql | an SQL statement to execute - an SQL INSERT, UPDATE, DELETE or a statement which returns nothing |
|---|---|
| columnNames | an array of column names in the inserted row which should be
made available for retrieval via the
getGeneratedKeys method. |
| SQLException | if an error occurs accessing the database or if the statement produces a ResultSet |
|---|
Executes the supplied SQL statement. This method allows control of whether auto-generated Keys should be made available for retrieval.
| sql | an SQL statement to execute - an SQL INSERT, UPDATE, DELETE or a statement which does not return anything. |
|---|---|
| autoGeneratedKeys | a flag that indicates whether to allow retrieval of auto generated keys. Parameter must be one of Statement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS |
| SQLException | if an error occurs accessing the database or if the statement produces a ResultSet |
|---|
Gets the Connection that produced this Statement.
| SQLException | if an error occurs accessing the database |
|---|
Gets the default direction for fetching rows for ResultSets generated from this Statement.
| SQLException | if an error occurs accessing the database |
|---|
Gets the default number of rows for a fetch for the ResultSet objects returned from this Statement.
| SQLException | if an error occurs accessing the database |
|---|
Returns auto generated keys created by executing this Statement.
| SQLException | if an error occurs accessing the database |
|---|
Gets the maximum number of bytes which can be returned for values from Character and Binary values in a ResultSet derived from this Statement. This limit applies to BINARY, VARBINARY, LONGVARBINARY, CHAR, VARCHAR, and LONGVARCHAR types. Any data exceeding the maximum size is abandoned without announcement.
| SQLException | if an error occurs accessing the database |
|---|
Gets the maximum number of rows that a ResultSet can contain when produced from this Statement. If the limit is exceeded, the excess rows are discarded silently.
| SQLException | if an error occurs accessing the database |
|---|
Moves to this Statement's next result. Returns true if the next result is
a ResultSet. Any current ResultSet objects previously obtained with
getResultSet() are handled as indicated by a supplied Flag
parameter.
| current | a flag indicating what to do with existing ResultSets. This parameter must be one of Statement.CLOSE_ALL_RESULTS, Statement.CLOSE_CURRENT_RESULT or Statement.KEEP_CURRENT_RESULT. |
|---|
getUpdateCount will return -1.| SQLException | if an error occurs accessing the database |
|---|
Moves to this Statement's next result. Returns true if it is a ResultSet.
Any current ResultSet objects previously obtained with
getResultSet() are closed implicitly.
getUpdateCount will return -1.| SQLException | if an error occurs accessing the database |
|---|
Gets the timeout value for Statement execution. The JDBC driver will wait up to this value for the execution to complete - after the limit is exceeded an SQL Exception is thrown.
| SQLException | if an error occurs accessing the database |
|---|
Gets the current result. Should only be called once per result.
| SQLException | if an error occurs accessing the database |
|---|
Gets the concurrency setting for ResultSet objects generated by this Statement.
| SQLException | if an error occurs accessing the database |
|---|
Gets the cursor hold setting for ResultSet objects generated by this Statement.
| SQLException | if there is an error while accessing the database |
|---|
Gets the ResultSet type setting for ResultSets derived from this Statement.
| SQLException | if there is an error accessing the database |
|---|
Gets an update count for the current result if it is not a ResultSet.
| SQLException | if an error occurs accessing the database |
|---|
Retrieves the first SQLWarning reported by calls on this Statement.
If there are multiple warnings, subsequent warnings are chained to the first one.
The chain or warnings is cleared each time the Statement is executed.
Warnings associated with reads from the ResultSet returned from executing a Statement will be attached to the ResultSet, not the Statement object.
| SQLException | if an error occurs accessing the database |
|---|
Sets the SQL cursor name. This name is used by subsequent Statement execute methods.
Cursor names must be unique within one Connection.
With the Cursor name set, it can then be utilized in SQL positioned update or delete statements to determine the current row in a ResultSet generated from this Statement. The positioned update or delete must be done with a different Statement than this one.
| name | the Cursor name as a String, |
|---|
| SQLException | if an error occurs accessing the database |
|---|
Sets Escape Processing mode.
If Escape Processing is on, the JDBC driver will do escape substitution on an SQL statement before sending it for execution. This does not apply to PreparedStatements since they are processed when created, before this method can be called.
| enable | true to set escape processing mode on, false to turn it off. |
|---|
| SQLException | if an error occurs accessing the database |
|---|
Sets the fetch direction - a hint to the JDBC driver about the direction of processing of rows in ResultSets created by this Statement. The default fetch direction is FETCH_FORWARD.
| direction | which fetch direction to use. This parameter should be one of ResultSet.FETCH_UNKNOWN, ResultSet.FETCH_FORWARD or ResultSet.FETCH_REVERSE |
|---|
| SQLException | if there is an error while accessing the database or if the fetch direction is unrecognized |
|---|
Sets the fetch size. This is a hint to the JDBC driver about how many rows should be fetched from the database when more are required by application processing.
| rows | the number of rows that should be fetched. 0 tells the driver
to ignore the hint. Should be less than
getMaxRows for this statement. Should not be
negative. |
|---|
| SQLException | if an error occurs accessing the database, or if the rows parameter is out of range. |
|---|
Sets the maximum number of bytes for ResultSet columns that contain character or binary values. This applies to BINARY, VARBINARY, LONGVARBINARY, CHAR, VARCHAR, and LONGVARCHAR fields. Any data exceeding the maximum size is abandoned without announcement.
| max | the maximum field size in bytes. O means "no limit". |
|---|
| SQLException | if an error occurs accessing the database or the max value is <0. |
|---|
Sets the maximum number of rows that any ResultSet can contain. If the number of rows exceeds this value, the additional rows are silently discarded.
| max | the maximum number of rows. 0 means "no limit". |
|---|
| SQLException | if an error occurs accessing the database or if max <0. |
|---|
Sets the timeout, in seconds, for queries - how long the driver will allow for completion of a Statement execution. If the timeout is exceeded, the query will throw an SQLException.
| seconds | timeout in seconds. 0 means no timeout ("wait forever") |
|---|
| SQLException | if an error occurs accessing the database or if seconds <0. |
|---|