Class JdbcStatement
- java.lang.Object
-
- org.h2.message.TraceObject
-
- org.h2.jdbc.JdbcStatement
-
- All Implemented Interfaces:
java.lang.AutoCloseable,java.sql.Statement,java.sql.Wrapper,JdbcStatementBackwardsCompat
- Direct Known Subclasses:
JdbcPreparedStatement
public class JdbcStatement extends TraceObject implements java.sql.Statement, JdbcStatementBackwardsCompat
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
Fields Modifier and Type Field Description private java.util.ArrayList<java.lang.String>batchCommandsprivate booleancancelledprivate booleancloseOnCompletionprotected JdbcConnectionconnprivate booleanescapeProcessingprivate CommandInterfaceexecutingCommandprotected intfetchSizeprotected JdbcResultSetgeneratedKeysprotected longmaxRowsprotected JdbcResultSetresultSetprotected intresultSetConcurrencyprotected intresultSetTypeprotected Sessionsessionprotected longupdateCount-
Fields inherited from class org.h2.message.TraceObject
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
-
-
Constructor Summary
Constructors Constructor Description JdbcStatement(JdbcConnection conn, int id, int resultSetType, int resultSetConcurrency)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddBatch(java.lang.String sql)Adds a statement to the batch.voidcancel()Cancels a currently running statement.(package private) voidcheckClosed()Check if this connection is closed.private static voidcheckQuotes(java.lang.String identifier, int offset, int length)voidclearBatch()Clears the batch.voidclearWarnings()Clears all warnings.voidclose()Closes this statement.(package private) voidcloseIfCloseOnCompletion()private voidcloseInternal()protected voidcloseOldResultSet()INTERNAL.voidcloseOnCompletion()Specifies that this statement will be closed when its dependent result set is closed.java.lang.StringenquoteIdentifier(java.lang.String identifier, boolean alwaysQuote)Enquotes the specified identifier.booleanexecute(java.lang.String sql)Executes a statement and returns type of its result.booleanexecute(java.lang.String sql, int autoGeneratedKeys)Executes a statement and returns type of its result.booleanexecute(java.lang.String sql, int[] columnIndexes)Executes a statement and returns type of its result.booleanexecute(java.lang.String sql, java.lang.String[] columnNames)Executes a statement and returns type of its result.int[]executeBatch()Executes the batch.private longexecuteBatchElement(java.lang.String sql, java.sql.SQLException exception)private booleanexecuteInternal(java.lang.String sql, java.lang.Object generatedKeysRequest)long[]executeLargeBatch()Executes the batch.longexecuteLargeUpdate(java.lang.String sql)Executes a statement (insert, update, delete, create, drop) and returns the update count.longexecuteLargeUpdate(java.lang.String sql, int autoGeneratedKeys)Executes a statement and returns the update count.longexecuteLargeUpdate(java.lang.String sql, int[] columnIndexes)Executes a statement and returns the update count.longexecuteLargeUpdate(java.lang.String sql, java.lang.String[] columnNames)Executes a statement and returns the update count.java.sql.ResultSetexecuteQuery(java.lang.String sql)Executes a query (select statement) and returns the result set.intexecuteUpdate(java.lang.String sql)Executes a statement (insert, update, delete, create, drop) and returns the update count.intexecuteUpdate(java.lang.String sql, int autoGeneratedKeys)Executes a statement and returns the update count.intexecuteUpdate(java.lang.String sql, int[] columnIndexes)Executes a statement and returns the update count.intexecuteUpdate(java.lang.String sql, java.lang.String[] columnNames)Executes a statement and returns the update count.private longexecuteUpdateInternal(java.lang.String sql, java.lang.Object generatedKeysRequest)java.sql.ConnectiongetConnection()Returns the connection that created this object.intgetFetchDirection()Gets the fetch direction.intgetFetchSize()Gets the number of rows suggested to read in one step.java.sql.ResultSetgetGeneratedKeys()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 withStatement.RETURN_GENERATED_KEYS, column indexes, or column names.longgetLargeMaxRows()Gets the maximum number of rows for a ResultSet.longgetLargeUpdateCount()Returns the last update count of this statement.intgetMaxFieldSize()Gets the maximum number of bytes for a result set column.intgetMaxRows()Gets the maximum number of rows for a ResultSet.booleangetMoreResults()Moves to the next result set - however there is always only one result set.booleangetMoreResults(int current)Move to the next result set.intgetQueryTimeout()Gets the current query timeout in seconds.java.sql.ResultSetgetResultSet()Returns the last result set produces by this statement.intgetResultSetConcurrency()Gets the result set concurrency created by this object.intgetResultSetHoldability()Gets the result set holdability.intgetResultSetType()Gets the result set type.intgetUpdateCount()Returns the last update count of this statement.java.sql.SQLWarninggetWarnings()Gets the first warning reported by calls on this object.booleanisCancelled()Check whether the statement was cancelled.booleanisClosed()Returns whether this statement is closed.booleanisCloseOnCompletion()Returns whether this statement will be closed when its dependent result set is closed.booleanisPoolable()Returns whether this object is poolable.booleanisSimpleIdentifier(java.lang.String identifier)Checks if specified identifier may be used without quotes.booleanisWrapperFor(java.lang.Class<?> iface)Checks if unwrap can return an object of this class.(package private) voidonLazyResultSetClose(CommandInterface command, boolean closeCommand)Called when the result set is closed.voidsetCursorName(java.lang.String name)Sets the name of the cursor.voidsetEscapeProcessing(boolean enable)Enables or disables processing or JDBC escape syntax.(package private) voidsetExecutingStatement(CommandInterface c)INTERNAL.voidsetFetchDirection(int direction)Sets the fetch direction.voidsetFetchSize(int rows)Sets the number of rows suggested to read in one step.voidsetLargeMaxRows(long maxRows)Gets the maximum number of rows for a ResultSet.voidsetMaxFieldSize(int max)Sets the maximum number of bytes for a result set column.voidsetMaxRows(int maxRows)Gets the maximum number of rows for a ResultSet.voidsetPoolable(boolean poolable)Requests that this object should be pooled or not.voidsetQueryTimeout(int seconds)Sets the current query timeout in seconds.java.lang.StringtoString()INTERNAL<T> Tunwrap(java.lang.Class<T> iface)Return an object of this class if possible.-
Methods inherited from class org.h2.message.TraceObject
debugCode, debugCodeAssign, debugCodeCall, debugCodeCall, debugCodeCall, getNextId, getTraceId, getTraceObjectName, isDebugEnabled, isInfoEnabled, logAndConvert, quote, quoteArray, quoteBigDecimal, quoteBytes, quoteDate, quoteIntArray, quoteMap, quoteTime, quoteTimestamp, setTrace, unsupported
-
-
-
-
Field Detail
-
conn
protected JdbcConnection conn
-
session
protected Session session
-
resultSet
protected JdbcResultSet resultSet
-
maxRows
protected long maxRows
-
fetchSize
protected int fetchSize
-
updateCount
protected long updateCount
-
generatedKeys
protected JdbcResultSet generatedKeys
-
resultSetType
protected final int resultSetType
-
resultSetConcurrency
protected final int resultSetConcurrency
-
executingCommand
private volatile CommandInterface executingCommand
-
batchCommands
private java.util.ArrayList<java.lang.String> batchCommands
-
escapeProcessing
private boolean escapeProcessing
-
cancelled
private volatile boolean cancelled
-
closeOnCompletion
private boolean closeOnCompletion
-
-
Constructor Detail
-
JdbcStatement
JdbcStatement(JdbcConnection conn, int id, int resultSetType, int resultSetConcurrency)
-
-
Method Detail
-
executeQuery
public java.sql.ResultSet executeQuery(java.lang.String sql) throws java.sql.SQLExceptionExecutes a query (select statement) and returns the result set. If another result set exists for this statement, this will be closed (even if this statement fails).- Specified by:
executeQueryin interfacejava.sql.Statement- Parameters:
sql- the SQL statement to execute- Returns:
- the result set
- Throws:
java.sql.SQLException
-
executeUpdate
public final int executeUpdate(java.lang.String sql) throws java.sql.SQLExceptionExecutes a statement (insert, update, delete, create, drop) and returns the update count. This method is not allowed for prepared statements. If another result set exists for this statement, this will be closed (even if this statement fails). If auto commit is on, this statement will be committed. If the statement is a DDL statement (create, drop, alter) and does not throw an exception, the current transaction (if any) is committed after executing the statement.- Specified by:
executeUpdatein interfacejava.sql.Statement- Parameters:
sql- the SQL statement- 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
Statement.SUCCESS_NO_INFOif number of rows is too large for theintdata type) - Throws:
java.sql.SQLException- if a database error occurred or a select statement was executed- See Also:
executeLargeUpdate(String)
-
executeLargeUpdate
public final long executeLargeUpdate(java.lang.String sql) throws java.sql.SQLExceptionExecutes a statement (insert, update, delete, create, drop) and returns the update count. This method is not allowed for prepared statements. If another result set exists for this statement, this will be closed (even if this statement fails). If auto commit is on, this statement will be committed. If the statement is a DDL statement (create, drop, alter) and does not throw an exception, the current transaction (if any) is committed after executing the statement.- Specified by:
executeLargeUpdatein interfacejava.sql.Statement- Parameters:
sql- the SQL statement- 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)
- Throws:
java.sql.SQLException- if a database error occurred or a select statement was executed
-
executeUpdateInternal
private long executeUpdateInternal(java.lang.String sql, java.lang.Object generatedKeysRequest)
-
execute
public final boolean execute(java.lang.String sql) throws java.sql.SQLExceptionExecutes a statement and returns type of its result. This method is not allowed for prepared statements. If another result set exists for this statement, this will be closed (even if this statement fails). If the statement is a create or drop and does not throw an exception, the current transaction (if any) is committed after executing the statement. If auto commit is on, and the statement is not a select, this statement will be committed.- Specified by:
executein interfacejava.sql.Statement- Parameters:
sql- the SQL statement to execute- Returns:
- true if result is a result set, false otherwise
- Throws:
java.sql.SQLException
-
executeInternal
private boolean executeInternal(java.lang.String sql, java.lang.Object generatedKeysRequest)
-
getResultSet
public java.sql.ResultSet getResultSet() throws java.sql.SQLExceptionReturns the last result set produces by this statement.- Specified by:
getResultSetin interfacejava.sql.Statement- Returns:
- the result set
- Throws:
java.sql.SQLException
-
getUpdateCount
public final int getUpdateCount() throws java.sql.SQLExceptionReturns the last update count of this statement.- Specified by:
getUpdateCountin interfacejava.sql.Statement- 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
Statement.SUCCESS_NO_INFOif number of rows is too large for theintdata type) - Throws:
java.sql.SQLException- if this object is closed or invalid- See Also:
getLargeUpdateCount()
-
getLargeUpdateCount
public final long getLargeUpdateCount() throws java.sql.SQLExceptionReturns the last update count of this statement.- Specified by:
getLargeUpdateCountin interfacejava.sql.Statement- 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)
- Throws:
java.sql.SQLException- if this object is closed or invalid
-
close
public void close() throws java.sql.SQLExceptionCloses this statement. All result sets that where created by this statement become invalid after calling this method.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
closeInternal
private void closeInternal()
-
getConnection
public java.sql.Connection getConnection()
Returns the connection that created this object.- Specified by:
getConnectionin interfacejava.sql.Statement- Returns:
- the connection
-
getWarnings
public java.sql.SQLWarning getWarnings() throws java.sql.SQLExceptionGets the first warning reported by calls on this object. This driver does not support warnings, and will always return null.- Specified by:
getWarningsin interfacejava.sql.Statement- Returns:
- null
- Throws:
java.sql.SQLException
-
clearWarnings
public void clearWarnings() throws java.sql.SQLExceptionClears all warnings. As this driver does not support warnings, this call is ignored.- Specified by:
clearWarningsin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
setCursorName
public void setCursorName(java.lang.String name) throws java.sql.SQLExceptionSets the name of the cursor. This call is ignored.- Specified by:
setCursorNamein interfacejava.sql.Statement- Parameters:
name- ignored- Throws:
java.sql.SQLException- if this object is closed
-
setFetchDirection
public void setFetchDirection(int direction) throws java.sql.SQLExceptionSets the fetch direction. This call is ignored by this driver.- Specified by:
setFetchDirectionin interfacejava.sql.Statement- Parameters:
direction- ignored- Throws:
java.sql.SQLException- if this object is closed
-
getFetchDirection
public int getFetchDirection() throws java.sql.SQLExceptionGets the fetch direction.- Specified by:
getFetchDirectionin interfacejava.sql.Statement- Returns:
- FETCH_FORWARD
- Throws:
java.sql.SQLException- if this object is closed
-
getMaxRows
public int getMaxRows() throws java.sql.SQLExceptionGets the maximum number of rows for a ResultSet.- Specified by:
getMaxRowsin interfacejava.sql.Statement- Returns:
- the number of rows where 0 means no limit
- Throws:
java.sql.SQLException- if this object is closed
-
getLargeMaxRows
public long getLargeMaxRows() throws java.sql.SQLExceptionGets the maximum number of rows for a ResultSet.- Specified by:
getLargeMaxRowsin interfacejava.sql.Statement- Returns:
- the number of rows where 0 means no limit
- Throws:
java.sql.SQLException- if this object is closed
-
setMaxRows
public void setMaxRows(int maxRows) throws java.sql.SQLExceptionGets the maximum number of rows for a ResultSet.- Specified by:
setMaxRowsin interfacejava.sql.Statement- Parameters:
maxRows- the number of rows where 0 means no limit- Throws:
java.sql.SQLException- if this object is closed
-
setLargeMaxRows
public void setLargeMaxRows(long maxRows) throws java.sql.SQLExceptionGets the maximum number of rows for a ResultSet.- Specified by:
setLargeMaxRowsin interfacejava.sql.Statement- Parameters:
maxRows- the number of rows where 0 means no limit- Throws:
java.sql.SQLException- if this object is closed
-
setFetchSize
public void setFetchSize(int rows) throws java.sql.SQLExceptionSets the number of rows suggested to read in one step. This value cannot be higher than the maximum rows (setMaxRows) set by the statement or prepared statement, otherwise an exception is throws. Setting the value to 0 will set the default value. The default value can be changed using the system property h2.serverResultSetFetchSize.- Specified by:
setFetchSizein interfacejava.sql.Statement- Parameters:
rows- the number of rows- Throws:
java.sql.SQLException- if this object is closed
-
getFetchSize
public int getFetchSize() throws java.sql.SQLExceptionGets the number of rows suggested to read in one step.- Specified by:
getFetchSizein interfacejava.sql.Statement- Returns:
- the current fetch size
- Throws:
java.sql.SQLException- if this object is closed
-
getResultSetConcurrency
public int getResultSetConcurrency() throws java.sql.SQLExceptionGets the result set concurrency created by this object.- Specified by:
getResultSetConcurrencyin interfacejava.sql.Statement- Returns:
- the concurrency
- Throws:
java.sql.SQLException
-
getResultSetType
public int getResultSetType() throws java.sql.SQLExceptionGets the result set type.- Specified by:
getResultSetTypein interfacejava.sql.Statement- Returns:
- the type
- Throws:
java.sql.SQLException- if this object is closed
-
getMaxFieldSize
public int getMaxFieldSize() throws java.sql.SQLExceptionGets the maximum number of bytes for a result set column.- Specified by:
getMaxFieldSizein interfacejava.sql.Statement- Returns:
- always 0 for no limit
- Throws:
java.sql.SQLException- if this object is closed
-
setMaxFieldSize
public void setMaxFieldSize(int max) throws java.sql.SQLExceptionSets the maximum number of bytes for a result set column. This method does currently do nothing for this driver.- Specified by:
setMaxFieldSizein interfacejava.sql.Statement- Parameters:
max- the maximum size - ignored- Throws:
java.sql.SQLException- if this object is closed
-
setEscapeProcessing
public void setEscapeProcessing(boolean enable) throws java.sql.SQLExceptionEnables or disables processing or JDBC escape syntax. See also Connection.nativeSQL.- Specified by:
setEscapeProcessingin interfacejava.sql.Statement- Parameters:
enable- - true (default) or false (no conversion is attempted)- Throws:
java.sql.SQLException- if this object is closed
-
cancel
public void cancel() throws java.sql.SQLExceptionCancels a currently running statement. This method must be called from within another thread than the execute method. Operations on large objects are not interrupted, only operations that process many rows.- Specified by:
cancelin interfacejava.sql.Statement- Throws:
java.sql.SQLException- if this object is closed
-
isCancelled
public boolean isCancelled()
Check whether the statement was cancelled.- Returns:
- true if yes
-
getQueryTimeout
public int getQueryTimeout() throws java.sql.SQLExceptionGets the current query timeout in seconds. This method will return 0 if no query timeout is set. The result is rounded to the next second. For performance reasons, only the first call to this method will query the database. If the query timeout was changed in another way than calling setQueryTimeout, this method will always return the last value.- Specified by:
getQueryTimeoutin interfacejava.sql.Statement- Returns:
- the timeout in seconds
- Throws:
java.sql.SQLException- if this object is closed
-
setQueryTimeout
public void setQueryTimeout(int seconds) throws java.sql.SQLExceptionSets the current query timeout in seconds. Changing the value will affect all statements of this connection. This method does not commit a transaction, and rolling back a transaction does not affect this setting.- Specified by:
setQueryTimeoutin interfacejava.sql.Statement- Parameters:
seconds- the timeout in seconds - 0 means no timeout, values smaller 0 will throw an exception- Throws:
java.sql.SQLException- if this object is closed
-
addBatch
public void addBatch(java.lang.String sql) throws java.sql.SQLExceptionAdds a statement to the batch.- Specified by:
addBatchin interfacejava.sql.Statement- Parameters:
sql- the SQL statement- Throws:
java.sql.SQLException
-
clearBatch
public void clearBatch() throws java.sql.SQLExceptionClears the batch.- Specified by:
clearBatchin interfacejava.sql.Statement- Throws:
java.sql.SQLException
-
executeBatch
public int[] executeBatch() throws java.sql.SQLExceptionExecutes the batch. If one of the batched statements fails, this database will continue.- Specified by:
executeBatchin interfacejava.sql.Statement- Returns:
- the array of update counts
- Throws:
java.sql.SQLException- See Also:
executeLargeBatch()
-
executeLargeBatch
public long[] executeLargeBatch() throws java.sql.SQLExceptionExecutes the batch. If one of the batched statements fails, this database will continue.- Specified by:
executeLargeBatchin interfacejava.sql.Statement- Returns:
- the array of update counts
- Throws:
java.sql.SQLException
-
executeBatchElement
private long executeBatchElement(java.lang.String sql, java.sql.SQLException exception)
-
getGeneratedKeys
public java.sql.ResultSet getGeneratedKeys() throws java.sql.SQLExceptionReturn 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 withStatement.RETURN_GENERATED_KEYS, column indexes, or column names.Generated keys are only returned from from
INSERT,UPDATE,MERGE INTO, andMERGE INTO ... USINGcommands.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_KEYSis used H2 chooses columns to return automatically. The following columns are chosen:- Columns with sequences including
IDENTITYcolumns and columns withAUTO_INCREMENT. - Columns with other default values that are not evaluated into
constant expressions (like
DEFAULT RANDOM_UUID()). - Columns that are included into the PRIMARY KEY constraint.
Exact required columns for the returning result set may be specified on execution of command with names or indexes of columns.
- Specified by:
getGeneratedKeysin interfacejava.sql.Statement- Returns:
- the possibly empty result set with generated keys
- Throws:
java.sql.SQLException- if this object is closed
- Columns with sequences including
-
getMoreResults
public boolean getMoreResults() throws java.sql.SQLExceptionMoves to the next result set - however there is always only one result set. This call also closes the current result set (if there is one). Returns true if there is a next result set (that means - it always returns false).- Specified by:
getMoreResultsin interfacejava.sql.Statement- Returns:
- false
- Throws:
java.sql.SQLException- if this object is closed.
-
getMoreResults
public boolean getMoreResults(int current) throws java.sql.SQLExceptionMove to the next result set. This method always returns false.- Specified by:
getMoreResultsin interfacejava.sql.Statement- Parameters:
current- Statement.CLOSE_CURRENT_RESULT, Statement.KEEP_CURRENT_RESULT, or Statement.CLOSE_ALL_RESULTS- Returns:
- false
- Throws:
java.sql.SQLException
-
executeUpdate
public final int executeUpdate(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLExceptionExecutes a statement and returns the update count. This method is not allowed for prepared statements.- Specified by:
executeUpdatein interfacejava.sql.Statement- Parameters:
sql- the SQL statementautoGeneratedKeys-Statement.RETURN_GENERATED_KEYSif generated keys should be available for retrieval,Statement.NO_GENERATED_KEYSif generated keys should not be available- 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
Statement.SUCCESS_NO_INFOif number of rows is too large for theintdata type) - Throws:
java.sql.SQLException- if a database error occurred or a select statement was executed- See Also:
executeLargeUpdate(String, int)
-
executeLargeUpdate
public final long executeLargeUpdate(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLExceptionExecutes a statement and returns the update count. This method is not allowed for prepared statements.- Specified by:
executeLargeUpdatein interfacejava.sql.Statement- Parameters:
sql- the SQL statementautoGeneratedKeys-Statement.RETURN_GENERATED_KEYSif generated keys should be available for retrieval,Statement.NO_GENERATED_KEYSif generated keys should not be available- 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)
- Throws:
java.sql.SQLException- if a database error occurred or a select statement was executed
-
executeUpdate
public final int executeUpdate(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLExceptionExecutes a statement and returns the update count. This method is not allowed for prepared statements.- Specified by:
executeUpdatein interfacejava.sql.Statement- Parameters:
sql- the SQL statementcolumnIndexes- an array of column indexes indicating the columns with generated keys that should be returned from the inserted row- 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
Statement.SUCCESS_NO_INFOif number of rows is too large for theintdata type) - Throws:
java.sql.SQLException- if a database error occurred or a select statement was executed- See Also:
executeLargeUpdate(String, int[])
-
executeLargeUpdate
public final long executeLargeUpdate(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLExceptionExecutes a statement and returns the update count. This method is not allowed for prepared statements.- Specified by:
executeLargeUpdatein interfacejava.sql.Statement- Parameters:
sql- the SQL statementcolumnIndexes- an array of column indexes indicating the columns with generated keys that should be returned from the inserted row- 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)
- Throws:
java.sql.SQLException- if a database error occurred or a select statement was executed
-
executeUpdate
public final int executeUpdate(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLExceptionExecutes a statement and returns the update count. This method is not allowed for prepared statements.- Specified by:
executeUpdatein interfacejava.sql.Statement- Parameters:
sql- the SQL statementcolumnNames- an array of column names indicating the columns with generated keys that should be returned from the inserted row- 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
Statement.SUCCESS_NO_INFOif number of rows is too large for theintdata type) - Throws:
java.sql.SQLException- if a database error occurred or a select statement was executed- See Also:
executeLargeUpdate(String, String[])
-
executeLargeUpdate
public final long executeLargeUpdate(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLExceptionExecutes a statement and returns the update count. This method is not allowed for prepared statements.- Specified by:
executeLargeUpdatein interfacejava.sql.Statement- Parameters:
sql- the SQL statementcolumnNames- an array of column names indicating the columns with generated keys that should be returned from the inserted row- 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)
- Throws:
java.sql.SQLException- if a database error occurred or a select statement was executed
-
execute
public final boolean execute(java.lang.String sql, int autoGeneratedKeys) throws java.sql.SQLExceptionExecutes a statement and returns type of its result. This method is not allowed for prepared statements.- Specified by:
executein interfacejava.sql.Statement- Parameters:
sql- the SQL statementautoGeneratedKeys-Statement.RETURN_GENERATED_KEYSif generated keys should be available for retrieval,Statement.NO_GENERATED_KEYSif generated keys should not be available- Returns:
- true if result is a result set, false otherwise
- Throws:
java.sql.SQLException- if a database error occurred or a select statement was executed
-
execute
public final boolean execute(java.lang.String sql, int[] columnIndexes) throws java.sql.SQLExceptionExecutes a statement and returns type of its result. This method is not allowed for prepared statements.- Specified by:
executein interfacejava.sql.Statement- Parameters:
sql- the SQL statementcolumnIndexes- an array of column indexes indicating the columns with generated keys that should be returned from the inserted row- Returns:
- true if result is a result set, false otherwise
- Throws:
java.sql.SQLException- if a database error occurred or a select statement was executed
-
execute
public final boolean execute(java.lang.String sql, java.lang.String[] columnNames) throws java.sql.SQLExceptionExecutes a statement and returns type of its result. This method is not allowed for prepared statements.- Specified by:
executein interfacejava.sql.Statement- Parameters:
sql- the SQL statementcolumnNames- an array of column names indicating the columns with generated keys that should be returned from the inserted row- Returns:
- true if result is a result set, false otherwise
- Throws:
java.sql.SQLException- if a database error occurred or a select statement was executed
-
getResultSetHoldability
public int getResultSetHoldability() throws java.sql.SQLExceptionGets the result set holdability.- Specified by:
getResultSetHoldabilityin interfacejava.sql.Statement- Returns:
- the holdability
- Throws:
java.sql.SQLException
-
closeOnCompletion
public void closeOnCompletion() throws java.sql.SQLExceptionSpecifies that this statement will be closed when its dependent result set is closed.- Specified by:
closeOnCompletionin interfacejava.sql.Statement- Throws:
java.sql.SQLException- if this statement is closed
-
isCloseOnCompletion
public boolean isCloseOnCompletion() throws java.sql.SQLExceptionReturns whether this statement will be closed when its dependent result set is closed.- Specified by:
isCloseOnCompletionin interfacejava.sql.Statement- Returns:
trueif this statement will be closed when its dependent result set is closed- Throws:
java.sql.SQLException- if this statement is closed
-
closeIfCloseOnCompletion
void closeIfCloseOnCompletion()
-
checkClosed
void checkClosed()
Check if this connection is closed.- Throws:
DbException- if the connection or session is closed
-
closeOldResultSet
protected void closeOldResultSet()
INTERNAL. Close and old result set if there is still one open.
-
setExecutingStatement
void setExecutingStatement(CommandInterface c)
INTERNAL. Set the statement that is currently running.- Parameters:
c- the command
-
onLazyResultSetClose
void onLazyResultSetClose(CommandInterface command, boolean closeCommand)
Called when the result set is closed.- Parameters:
command- the commandcloseCommand- whether to close the command
-
isClosed
public boolean isClosed() throws java.sql.SQLExceptionReturns whether this statement is closed.- Specified by:
isClosedin interfacejava.sql.Statement- Returns:
- true if the statement is closed
- Throws:
java.sql.SQLException
-
unwrap
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLExceptionReturn an object of this class if possible.- Specified by:
unwrapin interfacejava.sql.Wrapper- Parameters:
iface- the class- Returns:
- this
- Throws:
java.sql.SQLException
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLExceptionChecks if unwrap can return an object of this class.- Specified by:
isWrapperForin interfacejava.sql.Wrapper- Parameters:
iface- the class- Returns:
- whether or not the interface is assignable from this class
- Throws:
java.sql.SQLException
-
isPoolable
public boolean isPoolable()
Returns whether this object is poolable.- Specified by:
isPoolablein interfacejava.sql.Statement- Returns:
- false
-
setPoolable
public void setPoolable(boolean poolable)
Requests that this object should be pooled or not. This call is ignored.- Specified by:
setPoolablein interfacejava.sql.Statement- Parameters:
poolable- the requested value
-
enquoteIdentifier
public java.lang.String enquoteIdentifier(java.lang.String identifier, boolean alwaysQuote) throws java.sql.SQLExceptionDescription copied from interface:JdbcStatementBackwardsCompatEnquotes the specified identifier.- Specified by:
enquoteIdentifierin interfaceJdbcStatementBackwardsCompat- Specified by:
enquoteIdentifierin interfacejava.sql.Statement- Parameters:
identifier- identifier to quote if required, may be quoted or unquotedalwaysQuote- iftrueidentifier will be quoted unconditionally- Returns:
- specified identifier quoted if required, explicitly requested, or if it was already quoted
- Throws:
java.lang.NullPointerException- if identifier isnulljava.sql.SQLException- if identifier is not a valid identifier
-
checkQuotes
private static void checkQuotes(java.lang.String identifier, int offset, int length)
-
isSimpleIdentifier
public boolean isSimpleIdentifier(java.lang.String identifier) throws java.sql.SQLExceptionDescription copied from interface:JdbcStatementBackwardsCompatChecks if specified identifier may be used without quotes.- Specified by:
isSimpleIdentifierin interfaceJdbcStatementBackwardsCompat- Specified by:
isSimpleIdentifierin interfacejava.sql.Statement- Parameters:
identifier- identifier to check- Returns:
- is specified identifier may be used without quotes
- Throws:
java.lang.NullPointerException- if identifier isnulljava.sql.SQLException- on failure
-
toString
public java.lang.String toString()
INTERNAL- Overrides:
toStringin classjava.lang.Object
-
-