Top Description Fields Constructors Methods
org.h2.jdbc

public Class JdbcStatement

extends TraceObject
implements Statement
Class Inheritance
All Implemented Interfaces
java.sql.Statement, java.lang.AutoCloseable, java.sql.Wrapper
Known Direct Subclasses
org.h2.jdbc.JdbcPreparedStatement
Imports
java.sql.Connection, .ResultSet, .SQLException, .SQLWarning, .Statement, java.util.ArrayList, org.h2.api.ErrorCode, org.h2.command.CommandInterface, org.h2.engine.Session, .SysProperties, org.h2.message.DbException, .TraceObject, org.h2.result.ResultInterface, .ResultWithGeneratedKeys, .SimpleResult, org.h2.util.ParserUtil, .StringUtils, .Utils

Represents a statement.

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);
}

Field Summary

Modifier and TypeField and Description
private ArrayList<String>
private volatile boolean
private boolean
protected JdbcConnection
private boolean
private volatile CommandInterface
protected int
protected JdbcResultSet
protected long
protected JdbcResultSet
protected final int
protected final int
protected Session
protected long
Inherited from org.h2.message.TraceObject:
ARRAYBLOBCALLABLE_STATEMENTCLOBCONNECTIONDATA_SOURCEDATABASE_META_DATAPARAMETER_META_DATAPREPARED_STATEMENTRESULT_SETRESULT_SET_META_DATASAVEPOINTSQLXMLSTATEMENTtraceXA_DATA_SOURCEXID

Constructor Summary

AccessConstructor and Description
pack-priv
JdbcStatement(JdbcConnection conn, int id, int resultSetType, int resultSetConcurrency)

Method Summary

Modifier and TypeMethod and Description
public void
addBatch(String
the SQL statement
sql
)

Implements java.sql.Statement.addBatch.

Adds a statement to the batch.

public void
cancel()

Implements java.sql.Statement.cancel.

Cancels a currently running statement.

pack-priv void
checkClosed()

Check if this connection is closed.

private static void
checkQuotes(String identifier, int offset, int length)

public void
clearBatch()

Implements java.sql.Statement.clearBatch.

Clears the batch.

public void
clearWarnings()

Implements java.sql.Statement.clearWarnings.

Clears all warnings.

public void
close()

Implements java.sql.Statement.close.

Closes this statement.

pack-priv void
private void
protected void
closeOldResultSet()

INTERNAL.

public void
closeOnCompletion()

Implements java.sql.Statement.closeOnCompletion.

Specifies that this statement will be closed when its dependent result set is closed.

public String

Returns:

specified identifier quoted if required, explicitly requested, or if it was already quoted
enquoteIdentifier
(String
identifier to quote if required, may be quoted or unquoted
identifier
,
boolean
if true identifier will be quoted unconditionally
alwaysQuote
)

Overrides default java.sql.Statement.enquoteIdentifier.

Returns a SQL identifier.

public final boolean

Returns:

true if result is a result set, false otherwise
execute
(String
the SQL statement to execute
sql
)

Implements java.sql.Statement.execute.

Executes a statement and returns type of its result.

public final boolean

Returns:

true if result is a result set, false otherwise
execute
(String
the SQL statement
sql
,
int
Statement#RETURN_GENERATED_KEYS if generated keys should be available for retrieval, Statement#NO_GENERATED_KEYS if generated keys should not be available
autoGeneratedKeys
)

Implements java.sql.Statement.execute.

Executes a statement and returns type of its result.

public final boolean

Returns:

true if result is a result set, false otherwise
execute
(String
the SQL statement
sql
,
int[]
an array of column indexes indicating the columns with generated keys that should be returned from the inserted row
columnIndexes
)

Implements java.sql.Statement.execute.

Executes a statement and returns type of its result.

public final boolean

Returns:

true if result is a result set, false otherwise
execute
(String
the SQL statement
sql
,
String[]
an array of column names indicating the columns with generated keys that should be returned from the inserted row
columnNames
)

Implements java.sql.Statement.execute.

Executes a statement and returns type of its result.

public int[]

Returns:

the array of update counts
executeBatch
()

Implements java.sql.Statement.executeBatch.

Executes the batch.

private boolean
executeInternal(String sql, Object generatedKeysRequest)

public long[]

Returns:

the array of update counts
executeLargeBatch
()

Overrides default java.sql.Statement.executeLargeBatch.

Executes the batch.

public final long

Returns:

the update count (number of affected rows by a DML statement or other statement able to return number of rows, or 0 if no rows were affected or the statement returned nothing)
executeLargeUpdate
(String
the SQL statement
sql
)

Overrides default java.sql.Statement.executeLargeUpdate.

Executes a statement (insert, update, delete, create, drop) and returns the update count.

public final long

Returns:

the update count (number of affected rows by a DML statement or other statement able to return number of rows, or 0 if no rows were affected or the statement returned nothing)
executeLargeUpdate
(String
the SQL statement
sql
,
int
Statement#RETURN_GENERATED_KEYS if generated keys should be available for retrieval, Statement#NO_GENERATED_KEYS if generated keys should not be available
autoGeneratedKeys
)

Overrides default java.sql.Statement.executeLargeUpdate.

Executes a statement and returns the update count.

public final long

Returns:

the update count (number of affected rows by a DML statement or other statement able to return number of rows, or 0 if no rows were affected or the statement returned nothing)
executeLargeUpdate
(String
the SQL statement
sql
,
int[]
an array of column indexes indicating the columns with generated keys that should be returned from the inserted row
columnIndexes
)

Overrides default java.sql.Statement.executeLargeUpdate.

Executes a statement and returns the update count.

public final long

Returns:

the update count (number of row affected by an insert, update or delete, or 0 if no rows or the statement was a create, drop, commit or rollback)
executeLargeUpdate
(String
the SQL statement
sql
,
String[]
an array of column names indicating the columns with generated keys that should be returned from the inserted row
columnNames
)

Overrides default java.sql.Statement.executeLargeUpdate.

Executes a statement and returns the update count.

public ResultSet

Returns:

the result set
executeQuery
(String
the SQL statement to execute
sql
)

Implements java.sql.Statement.executeQuery.

Executes a query (select statement) and returns the result set.

public final int

Returns:

the update count (number of affected rows by a DML statement or other statement able to return number of rows, or 0 if no rows were affected or the statement returned nothing, or SUCCESS_NO_INFO if number of rows is too large for the int data type)
executeUpdate
(String
the SQL statement
sql
)

Implements java.sql.Statement.executeUpdate.

Executes a statement (insert, update, delete, create, drop) and returns the update count.

public final int

Returns:

the update count (number of affected rows by a DML statement or other statement able to return number of rows, or 0 if no rows were affected or the statement returned nothing, or SUCCESS_NO_INFO if number of rows is too large for the int data type)
executeUpdate
(String
the SQL statement
sql
,
int
Statement#RETURN_GENERATED_KEYS if generated keys should be available for retrieval, Statement#NO_GENERATED_KEYS if generated keys should not be available
autoGeneratedKeys
)

Implements java.sql.Statement.executeUpdate.

Executes a statement and returns the update count.

public final int

Returns:

the update count (number of affected rows by a DML statement or other statement able to return number of rows, or 0 if no rows were affected or the statement returned nothing, or SUCCESS_NO_INFO if number of rows is too large for the int data type)
executeUpdate
(String
the SQL statement
sql
,
int[]
an array of column indexes indicating the columns with generated keys that should be returned from the inserted row
columnIndexes
)

Implements java.sql.Statement.executeUpdate.

Executes a statement and returns the update count.

public final int

Returns:

the update count (number of affected rows by a DML statement or other statement able to return number of rows, or 0 if no rows were affected or the statement returned nothing, or SUCCESS_NO_INFO if number of rows is too large for the int data type)
executeUpdate
(String
the SQL statement
sql
,
String[]
an array of column names indicating the columns with generated keys that should be returned from the inserted row
columnNames
)

Implements java.sql.Statement.executeUpdate.

Executes a statement and returns the update count.

private long
executeUpdateInternal(String sql, Object generatedKeysRequest)

public Connection

Returns:

the connection
getConnection
()

Implements java.sql.Statement.getConnection.

Returns the connection that created this object.

public int

Returns:

FETCH_FORWARD
getFetchDirection
()

Implements java.sql.Statement.getFetchDirection.

Gets the fetch direction.

public int

Returns:

the current fetch size
getFetchSize
()

Implements java.sql.Statement.getFetchSize.

Gets the number of rows suggested to read in one step.

public final ResultSet

Returns:

the possibly empty result set with generated keys
getGeneratedKeys
()

Implements java.sql.Statement.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.

public long

Returns:

the number of rows where 0 means no limit
getLargeMaxRows
()

Overrides default java.sql.Statement.getLargeMaxRows.

Gets the maximum number of rows for a ResultSet.

public final long

Returns:

the update count (number of affected rows by a DML statement or other statement able to return number of rows, or 0 if no rows were affected or the statement returned nothing, or -1 if statement was a query)
getLargeUpdateCount
()

Overrides default java.sql.Statement.getLargeUpdateCount.

Returns the last update count of this statement.

public int

Returns:

always 0 for no limit
getMaxFieldSize
()

Implements java.sql.Statement.getMaxFieldSize.

Gets the maximum number of bytes for a result set column.

public int

Returns:

the number of rows where 0 means no limit
getMaxRows
()

Implements java.sql.Statement.getMaxRows.

Gets the maximum number of rows for a ResultSet.

public boolean

Returns:

false
getMoreResults
()

Implements java.sql.Statement.getMoreResults.

Moves to the next result set - however there is always only one result set.

public boolean

Returns:

false
getMoreResults
(int
Statement.CLOSE_CURRENT_RESULT, Statement.KEEP_CURRENT_RESULT, or Statement.CLOSE_ALL_RESULTS
current
)

Implements java.sql.Statement.getMoreResults.

Move to the next result set.

public int

Returns:

the timeout in seconds
getQueryTimeout
()

Implements java.sql.Statement.getQueryTimeout.

Gets the current query timeout in seconds.

public ResultSet

Returns:

the result set
getResultSet
()

Implements java.sql.Statement.getResultSet.

Returns the last result set produces by this statement.

public int

Returns:

the concurrency
getResultSetConcurrency
()

Implements java.sql.Statement.getResultSetConcurrency.

Gets the result set concurrency created by this object.

public int

Returns:

the holdability
getResultSetHoldability
()

Implements java.sql.Statement.getResultSetHoldability.

Gets the result set holdability.

public int

Returns:

the type
getResultSetType
()

Implements java.sql.Statement.getResultSetType.

Gets the result set type.

public final int

Returns:

the update count (number of affected rows by a DML statement or other statement able to return number of rows, or 0 if no rows were affected or the statement returned nothing, or -1 if statement was a query, or SUCCESS_NO_INFO if number of rows is too large for the int data type)
getUpdateCount
()

Implements java.sql.Statement.getUpdateCount.

Returns the last update count of this statement.

public SQLWarning

Returns:

null
getWarnings
()

Implements java.sql.Statement.getWarnings.

Gets the first warning reported by calls on this object.

public boolean

Returns:

true if yes
isCancelled
()

Check whether the statement was cancelled.

public boolean

Returns:

true if the statement is closed
isClosed
()

Implements java.sql.Statement.isClosed.

Returns whether this statement is closed.

public boolean

Returns:

true if this statement will be closed when its dependent result set is closed
isCloseOnCompletion
()

Implements java.sql.Statement.isCloseOnCompletion.

Returns whether this statement will be closed when its dependent result set is closed.

public boolean

Returns:

false
isPoolable
()

Implements java.sql.Statement.isPoolable.

Returns whether this object is poolable.

public boolean

Returns:

is specified identifier may be used without quotes
isSimpleIdentifier
(String
identifier to check
identifier
)

Overrides default java.sql.Statement.isSimpleIdentifier.

Retrieves whether identifier is a simple SQL identifier.

public boolean

Returns:

whether or not the interface is assignable from this class
isWrapperFor
(Class<?>
the class
iface
)

Implements java.sql.Wrapper.isWrapperFor.

Checks if unwrap can return an object of this class.

pack-priv void
onLazyResultSetClose(CommandInterface
the command
command
,
boolean
whether to close the command
closeCommand
)

Called when the result set is closed.

public void
setCursorName(String
ignored
name
)

Implements java.sql.Statement.setCursorName.

Sets the name of the cursor.

public void
setEscapeProcessing(boolean
- true (default) or false (no conversion is attempted)
enable
)

Implements java.sql.Statement.setEscapeProcessing.

Enables or disables processing or JDBC escape syntax.

pack-priv void
setExecutingStatement(CommandInterface
the command
c
)

INTERNAL.

public void
setFetchDirection(int
ignored
direction
)

Implements java.sql.Statement.setFetchDirection.

Sets the fetch direction.

public void
setFetchSize(int
the number of rows
rows
)

Implements java.sql.Statement.setFetchSize.

Sets the number of rows suggested to read in one step.

public void
setLargeMaxRows(long
the number of rows where 0 means no limit
maxRows
)

Overrides default java.sql.Statement.setLargeMaxRows.

Gets the maximum number of rows for a ResultSet.

public void
setMaxFieldSize(int
the maximum size - ignored
max
)

Implements java.sql.Statement.setMaxFieldSize.

Sets the maximum number of bytes for a result set column.

public void
setMaxRows(int
the number of rows where 0 means no limit
maxRows
)

Implements java.sql.Statement.setMaxRows.

Gets the maximum number of rows for a ResultSet.

public void
setPoolable(boolean
the requested value
poolable
)

Implements java.sql.Statement.setPoolable.

Requests that this object should be pooled or not.

public void
setQueryTimeout(int
the timeout in seconds - 0 means no timeout, values smaller 0 will throw an exception
seconds
)

Implements java.sql.Statement.setQueryTimeout.

Sets the current query timeout in seconds.

public String
toString()

Overrides java.lang.Object.toString.

INTERNAL

public <T> T

Returns:

this
unwrap
(Class<T>
the class
iface
)

Implements java.sql.Wrapper.unwrap.

Return an object of this class if possible.

Inherited from org.h2.message.TraceObject:
debugCodedebugCodeAssigndebugCodeCalldebugCodeCalldebugCodeCallgetNextIdgetTraceIdgetTraceObjectNameisDebugEnabledisInfoEnabledlogAndConvertquotequoteArrayquoteBigDecimalquoteBytesquoteDatequoteIntArrayquoteMapquoteTimequoteTimestampsetTraceunsupported