public class JdbcStatement extends TraceObject implements java.sql.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);
}
| Modifier and Type | Field and Description |
|---|---|
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| Modifier and Type | Method and Description |
|---|---|
void |
addBatch(java.lang.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.
|
java.lang.String |
enquoteIdentifier(java.lang.String identifier,
boolean alwaysQuote)
Enquotes the specified identifier.
|
boolean |
execute(java.lang.String sql)
Executes a statement and returns type of its result.
|
boolean |
execute(java.lang.String sql,
int autoGeneratedKeys)
Executes a statement and returns type of its result.
|
boolean |
execute(java.lang.String sql,
int[] columnIndexes)
Executes a statement and returns type of its result.
|
boolean |
execute(java.lang.String sql,
java.lang.String[] columnNames)
Executes a statement and returns type of its result.
|
int[] |
executeBatch()
Executes the batch.
|
long[] |
executeLargeBatch()
Executes the batch.
|
long |
executeLargeUpdate(java.lang.String sql)
Executes a statement (insert, update, delete, create, drop)
and returns the update count.
|
long |
executeLargeUpdate(java.lang.String sql,
int autoGeneratedKeys)
Executes a statement and returns the update count.
|
long |
executeLargeUpdate(java.lang.String sql,
int[] columnIndexes)
Executes a statement and returns the update count.
|
long |
executeLargeUpdate(java.lang.String sql,
java.lang.String[] columnNames)
Executes a statement and returns the update count.
|
java.sql.ResultSet |
executeQuery(java.lang.String sql)
Executes a query (select statement) and returns the result set.
|
int |
executeUpdate(java.lang.String sql)
Executes a statement (insert, update, delete, create, drop)
and returns the update count.
|
int |
executeUpdate(java.lang.String sql,
int autoGeneratedKeys)
Executes a statement and returns the update count.
|
int |
executeUpdate(java.lang.String sql,
int[] columnIndexes)
Executes a statement and returns the update count.
|
int |
executeUpdate(java.lang.String sql,
java.lang.String[] columnNames)
Executes a statement and returns the update count.
|
java.sql.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.
|
java.sql.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.
|
java.sql.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.
|
java.sql.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(java.lang.String identifier)
Checks if specified identifier may be used without quotes.
|
boolean |
isWrapperFor(java.lang.Class<?> iface)
Checks if unwrap can return an object of this class.
|
void |
setCursorName(java.lang.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.
|
java.lang.String |
toString()
INTERNAL
|
<T> T |
unwrap(java.lang.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 java.sql.ResultSet executeQuery(java.lang.String sql)
throws java.sql.SQLException
executeQuery in interface java.sql.Statementsql - the SQL statement to executejava.sql.SQLExceptionpublic final int executeUpdate(java.lang.String sql)
throws java.sql.SQLException
executeUpdate in interface java.sql.Statementsql - the SQL statementStatement.SUCCESS_NO_INFO if number of rows is too large for the
int data type)java.sql.SQLException - if a database error occurred or a
select statement was executedexecuteLargeUpdate(String)public final long executeLargeUpdate(java.lang.String sql)
throws java.sql.SQLException
executeLargeUpdate in interface java.sql.Statementsql - the SQL statementjava.sql.SQLException - if a database error occurred or a
select statement was executedpublic final boolean execute(java.lang.String sql)
throws java.sql.SQLException
execute in interface java.sql.Statementsql - the SQL statement to executejava.sql.SQLExceptionpublic java.sql.ResultSet getResultSet()
throws java.sql.SQLException
getResultSet in interface java.sql.Statementjava.sql.SQLExceptionpublic final int getUpdateCount()
throws java.sql.SQLException
getUpdateCount in interface java.sql.StatementStatement.SUCCESS_NO_INFO if number of
rows is too large for the int data type)java.sql.SQLException - if this object is closed or invalidgetLargeUpdateCount()public final long getLargeUpdateCount()
throws java.sql.SQLException
getLargeUpdateCount in interface java.sql.Statementjava.sql.SQLException - if this object is closed or invalidpublic void close()
throws java.sql.SQLException
close in interface java.lang.AutoCloseableclose in interface java.sql.Statementjava.sql.SQLExceptionpublic java.sql.Connection getConnection()
getConnection in interface java.sql.Statementpublic java.sql.SQLWarning getWarnings()
throws java.sql.SQLException
getWarnings in interface java.sql.Statementjava.sql.SQLExceptionpublic void clearWarnings()
throws java.sql.SQLException
clearWarnings in interface java.sql.Statementjava.sql.SQLExceptionpublic void setCursorName(java.lang.String name)
throws java.sql.SQLException
setCursorName in interface java.sql.Statementname - ignoredjava.sql.SQLException - if this object is closedpublic void setFetchDirection(int direction)
throws java.sql.SQLException
setFetchDirection in interface java.sql.Statementdirection - ignoredjava.sql.SQLException - if this object is closedpublic int getFetchDirection()
throws java.sql.SQLException
getFetchDirection in interface java.sql.Statementjava.sql.SQLException - if this object is closedpublic int getMaxRows()
throws java.sql.SQLException
getMaxRows in interface java.sql.Statementjava.sql.SQLException - if this object is closedpublic long getLargeMaxRows()
throws java.sql.SQLException
getLargeMaxRows in interface java.sql.Statementjava.sql.SQLException - if this object is closedpublic void setMaxRows(int maxRows)
throws java.sql.SQLException
setMaxRows in interface java.sql.StatementmaxRows - the number of rows where 0 means no limitjava.sql.SQLException - if this object is closedpublic void setLargeMaxRows(long maxRows)
throws java.sql.SQLException
setLargeMaxRows in interface java.sql.StatementmaxRows - the number of rows where 0 means no limitjava.sql.SQLException - if this object is closedpublic void setFetchSize(int rows)
throws java.sql.SQLException
setFetchSize in interface java.sql.Statementrows - the number of rowsjava.sql.SQLException - if this object is closedpublic int getFetchSize()
throws java.sql.SQLException
getFetchSize in interface java.sql.Statementjava.sql.SQLException - if this object is closedpublic int getResultSetConcurrency()
throws java.sql.SQLException
getResultSetConcurrency in interface java.sql.Statementjava.sql.SQLExceptionpublic int getResultSetType()
throws java.sql.SQLException
getResultSetType in interface java.sql.Statementjava.sql.SQLException - if this object is closedpublic int getMaxFieldSize()
throws java.sql.SQLException
getMaxFieldSize in interface java.sql.Statementjava.sql.SQLException - if this object is closedpublic void setMaxFieldSize(int max)
throws java.sql.SQLException
setMaxFieldSize in interface java.sql.Statementmax - the maximum size - ignoredjava.sql.SQLException - if this object is closedpublic void setEscapeProcessing(boolean enable)
throws java.sql.SQLException
setEscapeProcessing in interface java.sql.Statementenable - - true (default) or false (no conversion is attempted)java.sql.SQLException - if this object is closedpublic void cancel()
throws java.sql.SQLException
cancel in interface java.sql.Statementjava.sql.SQLException - if this object is closedpublic boolean isCancelled()
public int getQueryTimeout()
throws java.sql.SQLException
getQueryTimeout in interface java.sql.Statementjava.sql.SQLException - if this object is closedpublic void setQueryTimeout(int seconds)
throws java.sql.SQLException
setQueryTimeout in interface java.sql.Statementseconds - the timeout in seconds - 0 means no timeout, values
smaller 0 will throw an exceptionjava.sql.SQLException - if this object is closedpublic void addBatch(java.lang.String sql)
throws java.sql.SQLException
addBatch in interface java.sql.Statementsql - the SQL statementjava.sql.SQLExceptionpublic void clearBatch()
throws java.sql.SQLException
clearBatch in interface java.sql.Statementjava.sql.SQLExceptionpublic int[] executeBatch()
throws java.sql.SQLException
executeBatch in interface java.sql.Statementjava.sql.SQLExceptionexecuteLargeBatch()public long[] executeLargeBatch()
throws java.sql.SQLException
executeLargeBatch in interface java.sql.Statementjava.sql.SQLExceptionpublic java.sql.ResultSet getGeneratedKeys()
throws java.sql.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 in interface java.sql.Statementjava.sql.SQLException - if this object is closedpublic boolean getMoreResults()
throws java.sql.SQLException
getMoreResults in interface java.sql.Statementjava.sql.SQLException - if this object is closed.public boolean getMoreResults(int current)
throws java.sql.SQLException
getMoreResults in interface java.sql.Statementcurrent - Statement.CLOSE_CURRENT_RESULT,
Statement.KEEP_CURRENT_RESULT,
or Statement.CLOSE_ALL_RESULTSjava.sql.SQLExceptionpublic final int executeUpdate(java.lang.String sql,
int autoGeneratedKeys)
throws java.sql.SQLException
executeUpdate in interface java.sql.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)java.sql.SQLException - if a database error occurred or a
select statement was executedexecuteLargeUpdate(String, int)public final long executeLargeUpdate(java.lang.String sql,
int autoGeneratedKeys)
throws java.sql.SQLException
executeLargeUpdate in interface java.sql.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 availablejava.sql.SQLException - if a database error occurred or a
select statement was executedpublic final int executeUpdate(java.lang.String sql,
int[] columnIndexes)
throws java.sql.SQLException
executeUpdate in interface java.sql.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)java.sql.SQLException - if a database error occurred or a
select statement was executedexecuteLargeUpdate(String, int[])public final long executeLargeUpdate(java.lang.String sql,
int[] columnIndexes)
throws java.sql.SQLException
executeLargeUpdate in interface java.sql.Statementsql - the SQL statementcolumnIndexes - an array of column indexes indicating the columns with generated
keys that should be returned from the inserted rowjava.sql.SQLException - if a database error occurred or a
select statement was executedpublic final int executeUpdate(java.lang.String sql,
java.lang.String[] columnNames)
throws java.sql.SQLException
executeUpdate in interface java.sql.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)java.sql.SQLException - if a database error occurred or a
select statement was executedexecuteLargeUpdate(String, String[])public final long executeLargeUpdate(java.lang.String sql,
java.lang.String[] columnNames)
throws java.sql.SQLException
executeLargeUpdate in interface java.sql.Statementsql - the SQL statementcolumnNames - an array of column names indicating the columns with generated
keys that should be returned from the inserted rowjava.sql.SQLException - if a database error occurred or a
select statement was executedpublic final boolean execute(java.lang.String sql,
int autoGeneratedKeys)
throws java.sql.SQLException
execute in interface java.sql.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 availablejava.sql.SQLException - if a database error occurred or a
select statement was executedpublic final boolean execute(java.lang.String sql,
int[] columnIndexes)
throws java.sql.SQLException
execute in interface java.sql.Statementsql - the SQL statementcolumnIndexes - an array of column indexes indicating the columns with generated
keys that should be returned from the inserted rowjava.sql.SQLException - if a database error occurred or a
select statement was executedpublic final boolean execute(java.lang.String sql,
java.lang.String[] columnNames)
throws java.sql.SQLException
execute in interface java.sql.Statementsql - the SQL statementcolumnNames - an array of column names indicating the columns with generated
keys that should be returned from the inserted rowjava.sql.SQLException - if a database error occurred or a
select statement was executedpublic int getResultSetHoldability()
throws java.sql.SQLException
getResultSetHoldability in interface java.sql.Statementjava.sql.SQLExceptionpublic void closeOnCompletion()
throws java.sql.SQLException
closeOnCompletion in interface java.sql.Statementjava.sql.SQLException - if this statement is closedpublic boolean isCloseOnCompletion()
throws java.sql.SQLException
isCloseOnCompletion in interface java.sql.Statementtrue if this statement will be closed when its dependent
result set is closedjava.sql.SQLException - if this statement is closedprotected void closeOldResultSet()
public boolean isClosed()
throws java.sql.SQLException
isClosed in interface java.sql.Statementjava.sql.SQLExceptionpublic <T> T unwrap(java.lang.Class<T> iface)
throws java.sql.SQLException
unwrap in interface java.sql.Wrapperiface - the classjava.sql.SQLExceptionpublic boolean isWrapperFor(java.lang.Class<?> iface)
throws java.sql.SQLException
isWrapperFor in interface java.sql.Wrapperiface - the classjava.sql.SQLExceptionpublic boolean isPoolable()
isPoolable in interface java.sql.Statementpublic void setPoolable(boolean poolable)
setPoolable in interface java.sql.Statementpoolable - the requested valuepublic java.lang.String enquoteIdentifier(java.lang.String identifier,
boolean alwaysQuote)
throws java.sql.SQLException
JdbcStatementBackwardsCompatenquoteIdentifier in interface JdbcStatementBackwardsCompatidentifier - identifier to quote if required, may be quoted or unquotedalwaysQuote - if true identifier will be quoted unconditionallyjava.lang.NullPointerException - if identifier is nulljava.sql.SQLException - if identifier is not a valid identifierpublic boolean isSimpleIdentifier(java.lang.String identifier)
throws java.sql.SQLException
JdbcStatementBackwardsCompatisSimpleIdentifier in interface JdbcStatementBackwardsCompatidentifier - identifier to checkjava.lang.NullPointerException - if identifier is nulljava.sql.SQLException - on failurepublic java.lang.String toString()
toString in class java.lang.Object