| java.sql.Statement
Statement | public interface Statement (Code) | | 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.
|
Field Summary | |
final public static int | CLOSE_ALL_RESULTS Passing this constant to getMoreResults implies that all ResultSet
objects previously kept open should be closed. | final public static int | CLOSE_CURRENT_RESULT | final public static int | EXECUTE_FAILED Indicates that an error was encountered during execution of a batch
statement. | final public static int | KEEP_CURRENT_RESULT Passing this constant to getMoreResults implies that the current
ResultSet object should not be closed. | final public static int | NO_GENERATED_KEYS Indicates that generated keys should not be accessible for retrieval. | final public static int | RETURN_GENERATED_KEYS Indicates that generated keys should be accessible for retrieval. | final public static 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. |
Method Summary | |
public void | addBatch(String sql) Adds a specified SQL commands to the list of commands for this Statement.
The list of commands is executed by invoking the
executeBatch method.
Parameters: sql - the SQL command as a String. | public void | cancel() Cancels this Statement execution if both the database and the JDBC driver
support aborting an SQL statement in flight. | public void | clearBatch() Clears the current list of SQL commands for this Statement. | public void | clearWarnings() Clears all SQLWarnings from this Statement. | public void | close() Releases this Statement's database and JDBC driver resources.
Using this method to release these resources as soon as possible is
strongly recommended. | public boolean | execute(String sql) Executes a supplied SQL statement. | public boolean | execute(String sql, int autoGeneratedKeys) Executes a supplied SQL statement. | public boolean | execute(String sql, int[] columnIndexes) Executes the supplied SQL statement. | public boolean | execute(String sql, String[] columnNames) Executes the supplied SQL statement. | public int[] | executeBatch() Submits a batch of SQL commands to the database. | public ResultSet | executeQuery(String sql) Executes a supplied SQL statement. | public int | executeUpdate(String sql) Executes the supplied SQL statement. | public int | executeUpdate(String sql, int autoGeneratedKeys) Executes the supplied SQL statement. | public int | executeUpdate(String sql, int[] columnIndexes) Executes the supplied SQL statement. | public int | executeUpdate(String sql, String[] columnNames) Executes the supplied SQL statement. | public Connection | getConnection() Gets the Connection that produced this Statement. | public int | getFetchDirection() Gets the default direction for fetching rows for ResultSets generated
from this Statement. | public int | getFetchSize() Gets the default number of rows for a fetch for the ResultSet objects
returned from this Statement. | public ResultSet | getGeneratedKeys() Returns auto generated keys created by executing this Statement. | public int | getMaxFieldSize() 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. | public int | getMaxRows() Gets the maximum number of rows that a ResultSet can contain when
produced from this Statement. | public boolean | getMoreResults() Moves to this Statement's next result. | public boolean | getMoreResults(int current) Moves to this Statement's next result. | public int | getQueryTimeout() Gets the timeout value for Statement execution. | public ResultSet | getResultSet() Gets the current result. | public int | getResultSetConcurrency() Gets the concurrency setting for ResultSet objects generated by this
Statement. | public int | getResultSetHoldability() Gets the cursor hold setting for ResultSet objects generated by this
Statement. | public int | getResultSetType() Gets the ResultSet type setting for ResultSets derived from this
Statement. | public int | getUpdateCount() Gets an update count for the current result if it is not a ResultSet.
the current result as an update count. | public SQLWarning | getWarnings() Retrieves the first SQLWarning reported by calls on this Statement. | public void | setCursorName(String name) Sets the SQL cursor name. | public void | setEscapeProcessing(boolean enable) 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. | public void | setFetchDirection(int direction) Sets the fetch direction - a hint to the JDBC driver about the direction
of processing of rows in ResultSets created by this Statement. | public void | setFetchSize(int rows) Sets the fetch size. | public void | setMaxFieldSize(int max) Sets the maximum number of bytes for ResultSet columns that contain
character or binary values. | public void | setMaxRows(int max) Sets the maximum number of rows that any ResultSet can contain. | public void | setQueryTimeout(int seconds) Sets the timeout, in seconds, for queries - how long the driver will
allow for completion of a Statement execution. |
CLOSE_ALL_RESULTS | final public static int CLOSE_ALL_RESULTS(Code) | | Passing this constant to getMoreResults implies that all ResultSet
objects previously kept open should be closed.
|
CLOSE_CURRENT_RESULT | final public static int CLOSE_CURRENT_RESULT(Code) | | Passing this constant to getMoreResults implies that the current
ResultSet object should be closed
|
EXECUTE_FAILED | final public static int EXECUTE_FAILED(Code) | | Indicates that an error was encountered during execution of a batch
statement.
|
KEEP_CURRENT_RESULT | final public static int KEEP_CURRENT_RESULT(Code) | | Passing this constant to getMoreResults implies that the current
ResultSet object should not be closed.
|
NO_GENERATED_KEYS | final public static int NO_GENERATED_KEYS(Code) | | Indicates that generated keys should not be accessible for retrieval.
|
RETURN_GENERATED_KEYS | final public static int RETURN_GENERATED_KEYS(Code) | | Indicates that generated keys should be accessible for retrieval.
|
SUCCESS_NO_INFO | final public static int SUCCESS_NO_INFO(Code) | | Indicates that a batch statement was executed with a successful result,
but a count of the number of rows it affected is unavailable.
|
addBatch | public void addBatch(String sql) throws SQLException(Code) | | Adds a specified SQL commands to the list of commands for this Statement.
The list of commands is executed by invoking the
executeBatch method.
Parameters: sql - the SQL command as a String. Typically an INSERT or UPDATEstatement. throws: SQLException - if an error occurs accessing the database or the databasedoes not support batch updates |
cancel | public void cancel() throws SQLException(Code) | | 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.
throws: SQLException - if an error occurs accessing the database |
clearBatch | public void clearBatch() throws SQLException(Code) | | Clears the current list of SQL commands for this Statement.
throws: SQLException - if an error occurs accessing the database or the databasedoes not support batch updates |
clearWarnings | public void clearWarnings() throws SQLException(Code) | | Clears all SQLWarnings from this Statement.
throws: SQLException - if an error occurs accessing the database |
close | public void close() throws SQLException(Code) | | 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.
throws: SQLException - if an error occurs accessing the database |
execute | public boolean execute(String sql) throws SQLException(Code) | | 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.
Parameters: sql - the SQL statement to execute true if the first result is a ResultSet, false if the firstresult is an update count or if there is no result throws: SQLException - if an error occurs accessing the database |
execute | public boolean execute(String sql, int autoGeneratedKeys) throws SQLException(Code) | | 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.
Parameters: sql - the SQL statement to execute Parameters: autoGeneratedKeys - a flag indicating whether to make auto generated keysavailable for retrieval. This parameter must be one ofStatement.NO_GENERATED_KEYS or Statement.RETURN_GENERATED_KEYS true if results exists and the first result is a ResultSet, falseif the first result is an update count or if there is no result throws: SQLException - if an error occurs accessing the database |
execute | public boolean execute(String sql, int[] columnIndexes) throws SQLException(Code) | | 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.
Parameters: sql - the SQL statement to execute Parameters: columnIndexes - an array of indexes of the columns in the inserted row whichshould be made available for retrieval via thegetGeneratedKeys method. true if the first result is a ResultSet, false if the firstresult is an update count or if there is no result throws: SQLException - if an error occurs accessing the database |
execute | public boolean execute(String sql, String[] columnNames) throws SQLException(Code) | | 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.
Parameters: sql - the SQL statement to execute Parameters: columnNames - an array of column names in the inserted row which should bemade available for retrieval via thegetGeneratedKeys method. true if the first result is a ResultSet, false if the firstresult is an update count or if there is no result throws: SQLException - if an error occurs accessing the database |
executeBatch | public int[] executeBatch() throws SQLException(Code) | | 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.
an array of update counts, with one entry for each command in thebatch. The elements are ordered according to the order in whichthe commands were added to the batch. - If the value of an element is >=0, the corresponding commandcompleted successfully and the value is the update count for thatcommand, which is the number of rows in the database affected bythe command.
- If the value is SUCCESS_NO_INFO, the command completedsuccessfully but the number of rows affected is unknown.
- If the value is EXECUTE_FAILED, the command failed.
throws: SQLException - if an error occurs accessing the database |
executeQuery | public ResultSet executeQuery(String sql) throws SQLException(Code) | | Executes a supplied SQL statement. Returns a single ResultSet.
Parameters: sql - an SQL statement to execute. Typically a SELECT statement a ResultSet containing the data produced by the SQL statement.Never null. throws: SQLException - if an error occurs accessing the database or if the statementproduces anything other than a single ResultSet |
executeUpdate | public int executeUpdate(String sql) throws SQLException(Code) | | Executes the supplied SQL statement. The statement may be an INSERT,
UPDATE or DELETE statement or a statement which returns nothing.
Parameters: sql - an SQL statement to execute - an SQL INSERT, UPDATE, DELETE ora statement which returns nothing the count of updated rows, or 0 for a statement that returnsnothing. throws: SQLException - if an error occurs accessing the database or if the statementproduces a ResultSet |
executeUpdate | public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException(Code) | | Executes the supplied SQL statement. This method allows control of
whether auto-generated Keys should be made available for retrieval.
Parameters: sql - an SQL statement to execute - an SQL INSERT, UPDATE, DELETE ora statement which does not return anything. Parameters: autoGeneratedKeys - a flag that indicates whether to allow retrieval of autogenerated keys. Parameter must be one ofStatement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS the number of updated rows, or 0 if the statement returnsnothing. throws: SQLException - if an error occurs accessing the database or if the statementproduces a ResultSet |
executeUpdate | public int executeUpdate(String sql, int[] columnIndexes) throws SQLException(Code) | | Executes the supplied SQL statement. This method allows retrieval of auto
generated keys specified by the supplied array of column indexes.
Parameters: sql - an SQL statement to execute - an SQL INSERT, UPDATE, DELETE ora statement which returns nothing Parameters: columnIndexes - an array of indexes of the columns in the inserted row whichshould be made available for retrieval via thegetGeneratedKeys method. the count of updated rows, or 0 for a statement that returnsnothing. throws: SQLException - if an error occurs accessing the database or if the statementproduces a ResultSet |
executeUpdate | public int executeUpdate(String sql, String[] columnNames) throws SQLException(Code) | | Executes the supplied SQL statement. This method allows retrieval of auto
generated keys specified by the supplied array of column names.
Parameters: sql - an SQL statement to execute - an SQL INSERT, UPDATE, DELETE ora statement which returns nothing Parameters: columnNames - an array of column names in the inserted row which should bemade available for retrieval via thegetGeneratedKeys method. the count of updated rows, or 0 for a statement that returnsnothing. throws: SQLException - if an error occurs accessing the database or if the statementproduces a ResultSet |
getConnection | public Connection getConnection() throws SQLException(Code) | | Gets the Connection that produced this Statement.
the Connection throws: SQLException - if an error occurs accessing the database |
getFetchDirection | public int getFetchDirection() throws SQLException(Code) | | Gets the default direction for fetching rows for ResultSets generated
from this Statement.
an integer describing the default fetch direction, one of:ResultSet.FETCH_FORWARD, ResultSet.FETCH_REVERSE,ResultSet.FETCH_UNKNOWN throws: SQLException - if an error occurs accessing the database |
getFetchSize | public int getFetchSize() throws SQLException(Code) | | Gets the default number of rows for a fetch for the ResultSet objects
returned from this Statement.
the default fetch size for ResultSets produced by this Statement throws: SQLException - if an error occurs accessing the database |
getGeneratedKeys | public ResultSet getGeneratedKeys() throws SQLException(Code) | | Returns auto generated keys created by executing this Statement.
a ResultSet containing the auto generated keys - empty if no keyswere generated by the Statement throws: SQLException - if an error occurs accessing the database |
getMaxFieldSize | public int getMaxFieldSize() throws SQLException(Code) | | 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.
the current size limit, where 0 means that there is no limit throws: SQLException - if an error occurs accessing the database |
getMaxRows | public int getMaxRows() throws SQLException(Code) | | 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.
the current row limit, where 0 means that there is no limit. throws: SQLException - if an error occurs accessing the database |
getMoreResults | public boolean getMoreResults() throws SQLException(Code) | | 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.
true if the next result is a ResultSet, false if the next resultis not a ResultSet or if there are no more results. Note that ifthere is no more data, this method will return false andgetUpdateCount will return -1. throws: SQLException - if an error occurs accessing the database |
getMoreResults | public boolean getMoreResults(int current) throws SQLException(Code) | | 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.
Parameters: current - a flag indicating what to do with existing ResultSets. Thisparameter must be one of Statement.CLOSE_ALL_RESULTS,Statement.CLOSE_CURRENT_RESULT orStatement.KEEP_CURRENT_RESULT. true if the next result exists and is a ResultSet, false if thenext result is not a ResultSet or if there are no more results.Note that if there is no more data, this method will return falseand getUpdateCount will return -1. throws: SQLException - if an error occurs accessing the database |
getQueryTimeout | public int getQueryTimeout() throws SQLException(Code) | | 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.
the current Query Timeout value, where 0 indicates that there isno current timeout. throws: SQLException - if an error occurs accessing the database |
getResultSet | public ResultSet getResultSet() throws SQLException(Code) | | Gets the current result. Should only be called once per result.
the ResultSet for the current result. null if the result is anupdate count or if there are no more results. throws: SQLException - if an error occurs accessing the database |
getResultSetConcurrency | public int getResultSetConcurrency() throws SQLException(Code) | | Gets the concurrency setting for ResultSet objects generated by this
Statement.
ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE throws: SQLException - if an error occurs accessing the database |
getResultSetHoldability | public int getResultSetHoldability() throws SQLException(Code) | | Gets the cursor hold setting for ResultSet objects generated by this
Statement.
ResultSet.HOLD_CURSORS_OVER_COMMIT orResultSet.CLOSE_CURSORS_AT_COMMIT throws: SQLException - if there is an error while accessing the database |
getResultSetType | public int getResultSetType() throws SQLException(Code) | | Gets the ResultSet type setting for ResultSets derived from this
Statement.
ResultSet.TYPE_FORWARD_ONLY for a ResultSet where the cursor canonly move forward, ResultSet.TYPE_SCROLL_INSENSITIVE for aResultSet which is Scrollable but is not sensitive to changesmade by others, ResultSet.TYPE_SCROLL_SENSITIVE for a ResultSetwhich is Scrollable but is sensitive to changes made by others throws: SQLException - if there is an error accessing the database |
getUpdateCount | public int getUpdateCount() throws SQLException(Code) | | Gets an update count for the current result if it is not a ResultSet.
the current result as an update count. -1 if the current resultis a ResultSet or if there are no more results throws: SQLException - if an error occurs accessing the database |
getWarnings | public SQLWarning getWarnings() throws SQLException(Code) | | 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.
an SQLWarning, null if there are no warnings throws: SQLException - if an error occurs accessing the database |
setCursorName | public void setCursorName(String name) throws SQLException(Code) | | 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.
Parameters: name - the Cursor name as a String, throws: SQLException - if an error occurs accessing the database |
setEscapeProcessing | public void setEscapeProcessing(boolean enable) throws SQLException(Code) | | 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.
Parameters: enable - true to set escape processing mode on, false to turn it off. throws: SQLException - if an error occurs accessing the database |
setFetchDirection | public void setFetchDirection(int direction) throws SQLException(Code) | | 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.
Parameters: direction - which fetch direction to use. This parameter should be one ofResultSet.FETCH_UNKNOWN, ResultSet.FETCH_FORWARD orResultSet.FETCH_REVERSE throws: SQLException - if there is an error while accessing the database or if thefetch direction is unrecognized |
setFetchSize | public void setFetchSize(int rows) throws SQLException(Code) | | 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.
Parameters: rows - the number of rows that should be fetched. 0 tells the driverto ignore the hint. Should be less thangetMaxRows for this statement. Should not benegative. throws: SQLException - if an error occurs accessing the database, or if the rowsparameter is out of range. |
setMaxFieldSize | public void setMaxFieldSize(int max) throws SQLException(Code) | | 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.
Parameters: max - the maximum field size in bytes. O means "no limit". throws: SQLException - if an error occurs accessing the database or the max value is<0. |
setMaxRows | public void setMaxRows(int max) throws SQLException(Code) | | 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.
Parameters: max - the maximum number of rows. 0 means "no limit". throws: SQLException - if an error occurs accessing the database or if max <0. |
setQueryTimeout | public void setQueryTimeout(int seconds) throws SQLException(Code) | | 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.
Parameters: seconds - timeout in seconds. 0 means no timeout ("wait forever") throws: SQLException - if an error occurs accessing the database or if seconds <0. |
|
|