public class JDBCStatement extends Object implements Statement
| Modifier and Type | Field and Description |
|---|---|
protected JDBCConnection |
conn |
protected int |
maxrows |
protected JDBCResultSet |
rs |
protected int |
updcnt |
CLOSE_ALL_RESULTS, CLOSE_CURRENT_RESULT, EXECUTE_FAILED, KEEP_CURRENT_RESULT, NO_GENERATED_KEYS, RETURN_GENERATED_KEYS, SUCCESS_NO_INFO| Constructor and Description |
|---|
JDBCStatement(JDBCConnection conn) |
| Modifier and Type | Method and Description |
|---|---|
void |
addBatch(String sql)
Adds a specified SQL command to the list of commands for this
Statement. |
void |
cancel()
Cancels this statement's execution if both the database and the JDBC
driver support aborting an SQL statement in flight.
|
void |
clearBatch()
Clears the current list of SQL commands for this statement.
|
void |
clearWarnings()
Clears all
SQLWarnings from this statement. |
void |
close()
Releases this statement's database and JDBC driver resources.
|
boolean |
execute(String sql)
Executes a supplied SQL statement.
|
boolean |
execute(String sql,
int autokeys)
Executes a supplied SQL statement.
|
boolean |
execute(String sql,
int[] colIndexes)
Executes the supplied SQL statement.
|
boolean |
execute(String sql,
String[] colIndexes)
Executes the supplied SQL statement.
|
int[] |
executeBatch()
Submits a batch of SQL commands to the database.
|
ResultSet |
executeQuery(String sql)
Executes a supplied SQL statement.
|
int |
executeUpdate(String sql)
Executes the supplied SQL statement.
|
int |
executeUpdate(String sql,
int autokeys)
Executes the supplied SQL statement.
|
int |
executeUpdate(String sql,
int[] colIndexes)
Executes the supplied SQL statement.
|
int |
executeUpdate(String sql,
String[] colIndexes)
Executes the supplied SQL statement.
|
Connection |
getConnection()
Gets the
Connection object which created this statement. |
int |
getFetchDirection()
Gets the default direction for fetching rows for
ResultSets
generated from this statement. |
int |
getFetchSize()
Gets the default number of rows for a fetch for the
ResultSet
objects returned from this statement. |
ResultSet |
getGeneratedKeys()
Returns auto generated keys created by executing this statement.
|
int |
getMaxFieldSize()
Gets the maximum number of bytes which can be returned as values from
character and binary type columns in a
ResultSet derived from this
statement. |
int |
getMaxRows()
Gets the maximum number of rows that a
ResultSet can contain when
produced from this statement. |
boolean |
getMoreResults()
Moves to this statement's next result.
|
boolean |
getMoreResults(int x)
Moves to this statement's next result.
|
int |
getQueryTimeout()
Gets the timeout value for the statement's execution time.
|
ResultSet |
getResultSet()
Gets the current result.
|
int |
getResultSetConcurrency()
Gets the concurrency setting for
ResultSet objects generated by
this statement. |
int |
getResultSetHoldability()
Gets the cursor hold setting for
ResultSet objects generated by
this statement. |
int |
getResultSetType()
Gets the
ResultSet type setting for ResultSets derived
from this statement. |
int |
getUpdateCount()
Gets an update count for the current result if it is not a
ResultSet. |
SQLWarning |
getWarnings()
Retrieves the first
SQLWarning reported by calls on this
statement. |
boolean |
isClosed()
Returns true if this statement has been closed, false otherwise.
|
boolean |
isPoolable()
Returns true if this statement is poolable, false otherwise.
|
boolean |
isWrapperFor(Class iface)
If the caller is a wrapper of the class or implements the given
interface, the methods return false and vice versa.
|
void |
setCursorName(String name)
Sets the SQL cursor name.
|
void |
setEscapeProcessing(boolean enable)
Sets Escape Processing mode.
|
void |
setFetchDirection(int fetchDirection)
Sets the fetch direction - a hint to the JDBC driver about the direction
of processing of rows in
ResultSets created by this statement. |
void |
setFetchSize(int fetchSize)
Sets the fetch size.
|
void |
setMaxFieldSize(int max)
Sets the maximum number of bytes for
ResultSet columns that
contain character or binary values. |
void |
setMaxRows(int max)
Sets the maximum number of rows that any
ResultSet can contain. |
void |
setPoolable(boolean yes)
Hints whether this statement should be pooled.
|
void |
setQueryTimeout(int seconds)
Sets the timeout, in seconds, for queries - how long the driver will
allow for completion of a statement execution.
|
<T> T |
unwrap(Class<T> iface)
Returns an object that implements the given interface.
|
protected JDBCConnection conn
protected JDBCResultSet rs
protected int updcnt
protected int maxrows
public JDBCStatement(JDBCConnection conn)
public void setFetchSize(int fetchSize)
throws SQLException
StatementsetFetchSize in interface StatementfetchSize - 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.public int getFetchSize()
throws SQLException
StatementResultSet
objects returned from this statement.getFetchSize in interface StatementResultSets produced by this
statement.SQLException - if an error occurs accessing the database.public int getMaxRows()
throws SQLException
StatementResultSet can contain when
produced from this statement. If the limit is exceeded, the excess rows
are discarded silently.getMaxRows in interface Statement0 means that there is no
limit.SQLException - if an error occurs accessing the database.public void setMaxRows(int max)
throws SQLException
StatementResultSet can contain.
If the number of rows exceeds this value, the additional rows are
silently discarded.setMaxRows in interface Statementmax - the maximum number of rows. 0 means "no limit".SQLException - if an error occurs accessing the database or if max < 0.public void setFetchDirection(int fetchDirection)
throws SQLException
StatementResultSets created by this statement.
The default fetch direction is FETCH_FORWARD.setFetchDirection in interface StatementfetchDirection - which fetch direction to use. This parameter should be one of
ResultSet.FETCH_UNKNOWNResultSet.FETCH_FORWARDResultSet.FETCH_REVERSESQLException - if there is an error while accessing the database or if the
fetch direction is unrecognized.public int getFetchDirection()
throws SQLException
StatementResultSets
generated from this statement.getFetchDirection in interface StatementSQLException - if an error occurs accessing the database.public int getResultSetConcurrency()
throws SQLException
StatementResultSet objects generated by
this statement.getResultSetConcurrency in interface StatementResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE.SQLException - if an error occurs accessing the database.public int getResultSetType()
throws SQLException
StatementResultSet type setting for ResultSets derived
from this statement.getResultSetType in interface StatementResultSet.TYPE_FORWARD_ONLY for a ResultSet where
the cursor can only move forwards, ResultSet.TYPE_SCROLL_INSENSITIVE for a ResultSet which
is scrollable but is not sensitive to changes made by others,
ResultSet.TYPE_SCROLL_SENSITIVE for a ResultSet
which is scrollable but is sensitive to changes made by others.SQLException - if there is an error accessing the database.public void setQueryTimeout(int seconds)
throws SQLException
StatementSQLException.setQueryTimeout in interface Statementseconds - timeout in seconds. 0 means no timeout ("wait forever")SQLException - if an error occurs accessing the database or if seconds <
0.public int getQueryTimeout()
throws SQLException
StatementException is thrown.getQueryTimeout in interface Statement0 indicates that
there is no current timeout.SQLException - if an error occurs accessing the database.public ResultSet getResultSet() throws SQLException
StatementgetResultSet in interface StatementResultSet for the current result. null if the
result is an update count or if there are no more results.SQLException - if an error occurs accessing the database.public ResultSet executeQuery(String sql) throws SQLException
StatementResultSet.executeQuery in interface Statementsql - an SQL statement to execute. Typically a SELECT
statementResultSet containing the data produced by the SQL
statement. Never null.SQLException - if an error occurs accessing the database or if the statement
produces anything other than a single ResultSet.public boolean execute(String sql) throws SQLException
StatementResultSets.
Use the getResultSet or getUpdateCount methods to get the
first result and getMoreResults to get any subsequent results.
execute in interface Statementsql - the SQL statement to executetrue if the first result is a ResultSet, false if the first result is an update count or if there is no
result.SQLException - if an error occurs accessing the database.public void cancel()
throws SQLException
Statementcancel in interface StatementSQLException - if an error occurs accessing the database.public void clearWarnings()
throws SQLException
StatementSQLWarnings from this statement.clearWarnings in interface StatementSQLException - if an error occurs accessing the database.public Connection getConnection() throws SQLException
StatementConnection object which created this statement.getConnection in interface StatementConnection through which this statement is
transmitted to the database.SQLException - if an error occurs accessing the database.public void addBatch(String sql) throws SQLException
StatementStatement.
The list of commands is executed by invoking the executeBatch
method.
addBatch in interface Statementsql - 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.public int[] executeBatch()
throws SQLException
Statement
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, following the "all or nothing" principle. 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.
executeBatch in interface Statement
SUCCESS_NO_INFO, the command
completed successfully but the number of rows affected is
unknown.
EXECUTE_FAILED, the command failed.
SQLException - if an error occurs accessing the database.public void clearBatch()
throws SQLException
StatementclearBatch in interface StatementSQLException - if an error occurs accessing the database or the database
does not support batch updates.public void close()
throws SQLException
StatementUsing this method to release these resources as soon as possible is strongly recommended.
One should not rely on the resources being automatically released when finalized during garbage collection. Doing so can result in unpredictable behavior for the application.
close in interface AutoCloseableclose in interface StatementSQLException - if an error occurs accessing the database.public int executeUpdate(String sql) throws SQLException
StatementINSERT, UPDATE or DELETE statement or a statement which
returns nothing.executeUpdate in interface Statementsql - an SQL statement to execute - an SQL INSERT, UPDATE, DELETE or a statement which returns nothingSQLException - if an error occurs accessing the database or if the statement
produces a ResultSet.public int getMaxFieldSize()
throws SQLException
StatementResultSet 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.getMaxFieldSize in interface Statement0 means that there is no
limit.SQLException - if an error occurs accessing the database.public boolean getMoreResults()
throws SQLException
Statementtrue if it is a
ResultSet. Any current ResultSet objects previously
obtained with getResultSet() are closed implicitly.getMoreResults in interface Statementtrue if the next result is a ResultSet, false if the next result is not a ResultSet or if there
are no more results. Note that if there is no more data, this
method will return false and getUpdateCount will
return -1.SQLException - if an error occurs accessing the database.public int getUpdateCount()
throws SQLException
StatementResultSet.getUpdateCount in interface Statement-1 if the current
result is a ResultSet or if there are no more results.SQLException - if an error occurs accessing the database.public SQLWarning getWarnings() throws SQLException
StatementSQLWarning reported by calls on this
statement. If there are multiple warnings, subsequent warnings are
chained to the first one. The chain of warnings is cleared each time the
statement is executed.
Warnings associated with reads from the ResultSet returned from
executing the statement will be attached to the ResultSet, not the
statement object.
getWarnings in interface StatementSQLException - if an error occurs accessing the database.public void setCursorName(String name) throws SQLException
StatementCursor names must be unique within one Connection.
With the cursor name set, it can then be used 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.
setCursorName in interface Statementname - the Cursor name as a string,SQLException - if an error occurs accessing the database.public void setEscapeProcessing(boolean enable)
throws SQLException
Statement
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.
setEscapeProcessing in interface Statementenable - true to set escape processing mode on, false to turn it off.SQLException - if an error occurs accessing the database.public void setMaxFieldSize(int max)
throws SQLException
StatementResultSet 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.setMaxFieldSize in interface Statementmax - the maximum field size in bytes. 0 means "no limit".SQLException - if an error occurs accessing the database or the max
value is < 0.public boolean getMoreResults(int x)
throws SQLException
Statementtrue if the next
result is a ResultSet. Any current ResultSet objects
previously obtained with getResultSet() are handled as indicated
by a supplied Flag parameter.getMoreResults in interface Statementx - 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.true if the next result exists and is a ResultSet
, false if the next result is not a ResultSet or
if there are no more results. Note that if there is no more data,
this method will return false and getUpdateCount
will return -1.SQLException - if an error occurs accessing the database.public ResultSet getGeneratedKeys() throws SQLException
StatementgetGeneratedKeys in interface StatementResultSet containing the auto generated keys - empty if
no keys are generated by this statement.SQLException - if an error occurs accessing the database.public int executeUpdate(String sql, int autokeys) throws SQLException
StatementexecuteUpdate in interface Statementsql - an SQL statement to execute - an SQL INSERT, UPDATE, DELETE or a statement which does not return
anything.autokeys - 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_KEYSSQLException - if an error occurs accessing the database or if the statement
produces a ResultSet.public int executeUpdate(String sql, int[] colIndexes) throws SQLException
StatementexecuteUpdate in interface Statementsql - an SQL statement to execute - an SQL INSERT, UPDATE, DELETE or a statement which returns nothingcolIndexes - 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.public int executeUpdate(String sql, String[] colIndexes) throws SQLException
StatementexecuteUpdate in interface Statementsql - an SQL statement to execute - an SQL INSERT, UPDATE, DELETE or a statement which returns nothingcolIndexes - 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.public boolean execute(String sql, int autokeys) throws SQLException
StatementResultSets. 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.
execute in interface Statementsql - the SQL statement to execute.autokeys - 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.true if results exists and the first result is a ResultSet, false if the first result is an update count
or if there is no result.SQLException - if an error occurs accessing the database.public boolean execute(String sql, int[] colIndexes) throws SQLException
StatementResultSets. 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.
execute in interface Statementsql - the SQL statement to execute.colIndexes - an array of indexes of the columns in the inserted row which
should be made available for retrieval via the getGeneratedKeys method.true if the first result is a ResultSet, false if the first result is an update count or if there is no
result.SQLException - if an error occurs accessing the database.public boolean execute(String sql, String[] colIndexes) throws SQLException
StatementResultSets. 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.
execute in interface Statementsql - the SQL statement to execute.colIndexes - an array of column names in the inserted row which should be
made available for retrieval via the getGeneratedKeys
method.true if the first result is a ResultSet, false if the first result is an update count or if there is no
resultSQLException - if an error occurs accessing the database.public int getResultSetHoldability()
throws SQLException
StatementResultSet objects generated by
this statement.getResultSetHoldability in interface StatementResultSet.HOLD_CURSORS_OVER_COMMIT or ResultSet.CLOSE_CURSORS_AT_COMMITSQLException - if there is an error while accessing the database.public boolean isClosed()
throws SQLException
StatementisClosed in interface StatementSQLExceptionpublic void setPoolable(boolean yes)
throws SQLException
StatementStatement,
but true for CallableStatement and PreparedStatement. Pool manager
implementations may or may not honor this hint.setPoolable in interface StatementSQLExceptionpublic boolean isPoolable()
throws SQLException
StatementisPoolable in interface StatementSQLExceptionpublic <T> T unwrap(Class<T> iface) throws SQLException
Wrapperunwrap in interface Wrapperiface - -
the class that defines the interfaceSQLException - -
if there is no object implementing the specific interfacepublic boolean isWrapperFor(Class iface) throws SQLException
WrapperisWrapperFor in interface Wrapperiface - -
the class that defines the interfaceSQLException - -
when an error occurs when judges the object