public class JdbcStatement extends TraceObject implements Statement, JdbcStatementBackwardsCompat
Thread safety: the statement is not thread-safe. If the same statement is used by multiple threads access to it must be synchronized. The single synchronized block must include execution of the command and all operations with its result.
synchronized (stat) {
try (ResultSet rs = stat.executeQuery(queryString)) {
while (rs.next) {
// Do something
}
}
}
synchronized (stat) {
updateCount = stat.executeUpdate(commandString);
}
| 限定符和类型 | 字段和说明 |
|---|---|
protected JdbcConnection |
conn |
protected int |
fetchSize |
protected JdbcResultSet |
generatedKeys |
protected long |
maxRows |
protected JdbcResultSet |
resultSet |
protected int |
resultSetConcurrency |
protected int |
resultSetType |
protected Session |
session |
protected long |
updateCount |
ARRAY, BLOB, CALLABLE_STATEMENT, CLOB, CONNECTION, DATA_SOURCE, DATABASE_META_DATA, PARAMETER_META_DATA, PREPARED_STATEMENT, RESULT_SET, RESULT_SET_META_DATA, SAVEPOINT, SQLXML, STATEMENT, trace, XA_DATA_SOURCE, XID| 限定符和类型 | 方法和说明 |
|---|---|
void |
addBatch(String sql)
Adds a statement to the batch.
|
void |
cancel()
Cancels a currently running statement.
|
void |
clearBatch()
Clears the batch.
|
void |
clearWarnings()
Clears all warnings.
|
void |
close()
Closes this statement.
|
protected void |
closeOldResultSet()
INTERNAL.
|
void |
closeOnCompletion()
Specifies that this statement will be closed when its dependent result
set is closed.
|
String |
enquoteIdentifier(String identifier,
boolean alwaysQuote)
Enquotes the specified identifier.
|
boolean |
execute(String sql)
Executes a statement and returns type of its result.
|
boolean |
execute(String sql,
int autoGeneratedKeys)
Executes a statement and returns type of its result.
|
boolean |
execute(String sql,
int[] columnIndexes)
Executes a statement and returns type of its result.
|
boolean |
execute(String sql,
String[] columnNames)
Executes a statement and returns type of its result.
|
int[] |
executeBatch()
Executes the batch.
|
long[] |
executeLargeBatch()
Executes the batch.
|
long |
executeLargeUpdate(String sql)
Executes a statement (insert, update, delete, create, drop)
and returns the update count.
|
long |
executeLargeUpdate(String sql,
int autoGeneratedKeys)
Executes a statement and returns the update count.
|
long |
executeLargeUpdate(String sql,
int[] columnIndexes)
Executes a statement and returns the update count.
|
long |
executeLargeUpdate(String sql,
String[] columnNames)
Executes a statement and returns the update count.
|
ResultSet |
executeQuery(String sql)
Executes a query (select statement) and returns the result set.
|
int |
executeUpdate(String sql)
Executes a statement (insert, update, delete, create, drop)
and returns the update count.
|
int |
executeUpdate(String sql,
int autoGeneratedKeys)
Executes a statement and returns the update count.
|
int |
executeUpdate(String sql,
int[] columnIndexes)
Executes a statement and returns the update count.
|
int |
executeUpdate(String sql,
String[] columnNames)
Executes a statement and returns the update count.
|
Connection |
getConnection()
Returns the connection that created this object.
|
int |
getFetchDirection()
Gets the fetch direction.
|
int |
getFetchSize()
Gets the number of rows suggested to read in one step.
|
ResultSet |
getGeneratedKeys()
Return a result set with generated keys from the latest executed command
or an empty result set if keys were not generated or were not requested
with
Statement.RETURN_GENERATED_KEYS, column indexes, or column
names. |
long |
getLargeMaxRows()
Gets the maximum number of rows for a ResultSet.
|
long |
getLargeUpdateCount()
Returns the last update count of this statement.
|
int |
getMaxFieldSize()
Gets the maximum number of bytes for a result set column.
|
int |
getMaxRows()
Gets the maximum number of rows for a ResultSet.
|
boolean |
getMoreResults()
Moves to the next result set - however there is always only one result
set.
|
boolean |
getMoreResults(int current)
Move to the next result set.
|
int |
getQueryTimeout()
Gets the current query timeout in seconds.
|
ResultSet |
getResultSet()
Returns the last result set produces by this statement.
|
int |
getResultSetConcurrency()
Gets the result set concurrency created by this object.
|
int |
getResultSetHoldability()
Gets the result set holdability.
|
int |
getResultSetType()
Gets the result set type.
|
int |
getUpdateCount()
Returns the last update count of this statement.
|
SQLWarning |
getWarnings()
Gets the first warning reported by calls on this object.
|
boolean |
isCancelled()
Check whether the statement was cancelled.
|
boolean |
isClosed()
Returns whether this statement is closed.
|
boolean |
isCloseOnCompletion()
Returns whether this statement will be closed when its dependent result
set is closed.
|
boolean |
isPoolable()
Returns whether this object is poolable.
|
boolean |
isSimpleIdentifier(String identifier)
Checks if specified identifier may be used without quotes.
|
boolean |
isWrapperFor(Class<?> iface)
Checks if unwrap can return an object of this class.
|
void |
setCursorName(String name)
Sets the name of the cursor.
|
void |
setEscapeProcessing(boolean enable)
Enables or disables processing or JDBC escape syntax.
|
void |
setFetchDirection(int direction)
Sets the fetch direction.
|
void |
setFetchSize(int rows)
Sets the number of rows suggested to read in one step.
|
void |
setLargeMaxRows(long maxRows)
Gets the maximum number of rows for a ResultSet.
|
void |
setMaxFieldSize(int max)
Sets the maximum number of bytes for a result set column.
|
void |
setMaxRows(int maxRows)
Gets the maximum number of rows for a ResultSet.
|
void |
setPoolable(boolean poolable)
Requests that this object should be pooled or not.
|
void |
setQueryTimeout(int seconds)
Sets the current query timeout in seconds.
|
String |
toString()
INTERNAL
|
<T> T |
unwrap(Class<T> iface)
Return an object of this class if possible.
|
debugCode, debugCodeAssign, debugCodeCall, debugCodeCall, debugCodeCall, getNextId, getTraceId, getTraceObjectName, isDebugEnabled, isInfoEnabled, logAndConvert, quote, quoteArray, quoteBigDecimal, quoteBytes, quoteDate, quoteIntArray, quoteMap, quoteTime, quoteTimestamp, setTrace, unsupportedprotected JdbcConnection conn
protected Session session
protected JdbcResultSet resultSet
protected long maxRows
protected int fetchSize
protected long updateCount
protected JdbcResultSet generatedKeys
protected final int resultSetType
protected final int resultSetConcurrency
public ResultSet executeQuery(String sql) throws SQLException
executeQuery 在接口中 Statementsql - the SQL statement to executeSQLExceptionpublic final int executeUpdate(String sql) throws SQLException
executeUpdate 在接口中 Statementsql - the SQL statementStatement.SUCCESS_NO_INFO if number of rows is too large for the
int data type)SQLException - if a database error occurred or a
select statement was executedexecuteLargeUpdate(String)public final long executeLargeUpdate(String sql) throws SQLException
executeLargeUpdate 在接口中 Statementsql - the SQL statementSQLException - if a database error occurred or a
select statement was executedpublic final boolean execute(String sql) throws SQLException
execute 在接口中 Statementsql - the SQL statement to executeSQLExceptionpublic ResultSet getResultSet() throws SQLException
getResultSet 在接口中 StatementSQLExceptionpublic final int getUpdateCount()
throws SQLException
getUpdateCount 在接口中 StatementStatement.SUCCESS_NO_INFO if number of
rows is too large for the int data type)SQLException - if this object is closed or invalidgetLargeUpdateCount()public final long getLargeUpdateCount()
throws SQLException
getLargeUpdateCount 在接口中 StatementSQLException - if this object is closed or invalidpublic void close()
throws SQLException
close 在接口中 AutoCloseableclose 在接口中 StatementSQLExceptionpublic Connection getConnection()
getConnection 在接口中 Statementpublic SQLWarning getWarnings() throws SQLException
getWarnings 在接口中 StatementSQLExceptionpublic void clearWarnings()
throws SQLException
clearWarnings 在接口中 StatementSQLExceptionpublic void setCursorName(String name) throws SQLException
setCursorName 在接口中 Statementname - ignoredSQLException - if this object is closedpublic void setFetchDirection(int direction)
throws SQLException
setFetchDirection 在接口中 Statementdirection - ignoredSQLException - if this object is closedpublic int getFetchDirection()
throws SQLException
getFetchDirection 在接口中 StatementSQLException - if this object is closedpublic int getMaxRows()
throws SQLException
getMaxRows 在接口中 StatementSQLException - if this object is closedpublic long getLargeMaxRows()
throws SQLException
getLargeMaxRows 在接口中 StatementSQLException - if this object is closedpublic void setMaxRows(int maxRows)
throws SQLException
setMaxRows 在接口中 StatementmaxRows - the number of rows where 0 means no limitSQLException - if this object is closedpublic void setLargeMaxRows(long maxRows)
throws SQLException
setLargeMaxRows 在接口中 StatementmaxRows - the number of rows where 0 means no limitSQLException - if this object is closedpublic void setFetchSize(int rows)
throws SQLException
setFetchSize 在接口中 Statementrows - the number of rowsSQLException - if this object is closedpublic int getFetchSize()
throws SQLException
getFetchSize 在接口中 StatementSQLException - if this object is closedpublic int getResultSetConcurrency()
throws SQLException
getResultSetConcurrency 在接口中 StatementSQLExceptionpublic int getResultSetType()
throws SQLException
getResultSetType 在接口中 StatementSQLException - if this object is closedpublic int getMaxFieldSize()
throws SQLException
getMaxFieldSize 在接口中 StatementSQLException - if this object is closedpublic void setMaxFieldSize(int max)
throws SQLException
setMaxFieldSize 在接口中 Statementmax - the maximum size - ignoredSQLException - if this object is closedpublic void setEscapeProcessing(boolean enable)
throws SQLException
setEscapeProcessing 在接口中 Statementenable - - true (default) or false (no conversion is attempted)SQLException - if this object is closedpublic void cancel()
throws SQLException
cancel 在接口中 StatementSQLException - if this object is closedpublic boolean isCancelled()
public int getQueryTimeout()
throws SQLException
getQueryTimeout 在接口中 StatementSQLException - if this object is closedpublic void setQueryTimeout(int seconds)
throws SQLException
setQueryTimeout 在接口中 Statementseconds - the timeout in seconds - 0 means no timeout, values
smaller 0 will throw an exceptionSQLException - if this object is closedpublic void addBatch(String sql) throws SQLException
addBatch 在接口中 Statementsql - the SQL statementSQLExceptionpublic void clearBatch()
throws SQLException
clearBatch 在接口中 StatementSQLExceptionpublic int[] executeBatch()
throws SQLException
executeBatch 在接口中 StatementSQLExceptionexecuteLargeBatch()public long[] executeLargeBatch()
throws SQLException
executeLargeBatch 在接口中 StatementSQLExceptionpublic ResultSet getGeneratedKeys() throws SQLException
Statement.RETURN_GENERATED_KEYS, column indexes, or column
names.
Generated keys are only returned from from INSERT,
UPDATE, MERGE INTO, and MERGE INTO ... USING
commands.
If SQL command inserts or updates multiple rows with generated keys each such inserted or updated row is returned. Batch methods are also supported.
When Statement.RETURN_GENERATED_KEYS is used H2 chooses columns
to return automatically. The following columns are chosen:
IDENTITY columns and columns
with AUTO_INCREMENT.DEFAULT RANDOM_UUID()).Exact required columns for the returning result set may be specified on execution of command with names or indexes of columns.
getGeneratedKeys 在接口中 StatementSQLException - if this object is closedpublic boolean getMoreResults()
throws SQLException
getMoreResults 在接口中 StatementSQLException - if this object is closed.public boolean getMoreResults(int current)
throws SQLException
getMoreResults 在接口中 Statementcurrent - Statement.CLOSE_CURRENT_RESULT,
Statement.KEEP_CURRENT_RESULT,
or Statement.CLOSE_ALL_RESULTSSQLExceptionpublic final int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException
executeUpdate 在接口中 Statementsql - the SQL statementautoGeneratedKeys - Statement.RETURN_GENERATED_KEYS if generated keys should
be available for retrieval, Statement.NO_GENERATED_KEYS if
generated keys should not be availableStatement.SUCCESS_NO_INFO if number of rows is too large for the
int data type)SQLException - if a database error occurred or a
select statement was executedexecuteLargeUpdate(String, int)public final long executeLargeUpdate(String sql, int autoGeneratedKeys) throws SQLException
executeLargeUpdate 在接口中 Statementsql - the SQL statementautoGeneratedKeys - Statement.RETURN_GENERATED_KEYS if generated keys should
be available for retrieval, Statement.NO_GENERATED_KEYS if
generated keys should not be availableSQLException - if a database error occurred or a
select statement was executedpublic final int executeUpdate(String sql, int[] columnIndexes) throws SQLException
executeUpdate 在接口中 Statementsql - the SQL statementcolumnIndexes - an array of column indexes indicating the columns with generated
keys that should be returned from the inserted rowStatement.SUCCESS_NO_INFO if number of rows is too large for the
int data type)SQLException - if a database error occurred or a
select statement was executedexecuteLargeUpdate(String, int[])public final long executeLargeUpdate(String sql, int[] columnIndexes) throws SQLException
executeLargeUpdate 在接口中 Statementsql - the SQL statementcolumnIndexes - an array of column indexes indicating the columns with generated
keys that should be returned from the inserted rowSQLException - if a database error occurred or a
select statement was executedpublic final int executeUpdate(String sql, String[] columnNames) throws SQLException
executeUpdate 在接口中 Statementsql - the SQL statementcolumnNames - an array of column names indicating the columns with generated
keys that should be returned from the inserted rowStatement.SUCCESS_NO_INFO if number of rows is too large for the
int data type)SQLException - if a database error occurred or a
select statement was executedexecuteLargeUpdate(String, String[])public final long executeLargeUpdate(String sql, String[] columnNames) throws SQLException
executeLargeUpdate 在接口中 Statementsql - the SQL statementcolumnNames - an array of column names indicating the columns with generated
keys that should be returned from the inserted rowSQLException - if a database error occurred or a
select statement was executedpublic final boolean execute(String sql, int autoGeneratedKeys) throws SQLException
execute 在接口中 Statementsql - the SQL statementautoGeneratedKeys - Statement.RETURN_GENERATED_KEYS if generated keys should
be available for retrieval, Statement.NO_GENERATED_KEYS if
generated keys should not be availableSQLException - if a database error occurred or a
select statement was executedpublic final boolean execute(String sql, int[] columnIndexes) throws SQLException
execute 在接口中 Statementsql - the SQL statementcolumnIndexes - an array of column indexes indicating the columns with generated
keys that should be returned from the inserted rowSQLException - if a database error occurred or a
select statement was executedpublic final boolean execute(String sql, String[] columnNames) throws SQLException
execute 在接口中 Statementsql - the SQL statementcolumnNames - an array of column names indicating the columns with generated
keys that should be returned from the inserted rowSQLException - if a database error occurred or a
select statement was executedpublic int getResultSetHoldability()
throws SQLException
getResultSetHoldability 在接口中 StatementSQLExceptionpublic void closeOnCompletion()
throws SQLException
closeOnCompletion 在接口中 StatementSQLException - if this statement is closedpublic boolean isCloseOnCompletion()
throws SQLException
isCloseOnCompletion 在接口中 Statementtrue if this statement will be closed when its dependent
result set is closedSQLException - if this statement is closedprotected void closeOldResultSet()
public boolean isClosed()
throws SQLException
isClosed 在接口中 StatementSQLExceptionpublic <T> T unwrap(Class<T> iface) throws SQLException
unwrap 在接口中 Wrapperiface - the classSQLExceptionpublic boolean isWrapperFor(Class<?> iface) throws SQLException
isWrapperFor 在接口中 Wrapperiface - the classSQLExceptionpublic boolean isPoolable()
isPoolable 在接口中 Statementpublic void setPoolable(boolean poolable)
setPoolable 在接口中 Statementpoolable - the requested valuepublic String enquoteIdentifier(String identifier, boolean alwaysQuote) throws SQLException
JdbcStatementBackwardsCompatenquoteIdentifier 在接口中 JdbcStatementBackwardsCompatidentifier - identifier to quote if required, may be quoted or unquotedalwaysQuote - if true identifier will be quoted unconditionallyNullPointerException - if identifier is nullSQLException - if identifier is not a valid identifierpublic boolean isSimpleIdentifier(String identifier) throws SQLException
JdbcStatementBackwardsCompatisSimpleIdentifier 在接口中 JdbcStatementBackwardsCompatidentifier - identifier to checkNullPointerException - if identifier is nullSQLException - on failureCopyright © 2022. All rights reserved.