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>
batchCommands
private boolean
cancelled
private boolean
closeOnCompletion
protected JdbcConnection
conn
private boolean
escapeProcessing
private CommandInterface
executingCommand
protected int
fetchSize
protected JdbcResultSet
generatedKeys
protected long
maxRows
protected JdbcResultSet
resultSet
protected int
resultSetConcurrency
protected int
resultSetType
protected Session
session
protected long
updateCount
-
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 void
addBatch(java.lang.String sql)
Adds a statement to the batch.void
cancel()
Cancels a currently running statement.(package private) void
checkClosed()
Check if this connection is closed.private static void
checkQuotes(java.lang.String identifier, int offset, int length)
void
clearBatch()
Clears the batch.void
clearWarnings()
Clears all warnings.void
close()
Closes this statement.(package private) void
closeIfCloseOnCompletion()
private void
closeInternal()
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.private long
executeBatchElement(java.lang.String sql, java.sql.SQLException exception)
private boolean
executeInternal(java.lang.String sql, java.lang.Object generatedKeysRequest)
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.private long
executeUpdateInternal(java.lang.String sql, java.lang.Object generatedKeysRequest)
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 withStatement.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.(package private) void
onLazyResultSetClose(CommandInterface command, boolean closeCommand)
Called when the result set is closed.void
setCursorName(java.lang.String name)
Sets the name of the cursor.void
setEscapeProcessing(boolean enable)
Enables or disables processing or JDBC escape syntax.(package private) void
setExecutingStatement(CommandInterface c)
INTERNAL.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.-
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.SQLException
Executes 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:
executeQuery
in 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.SQLException
Executes 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:
executeUpdate
in 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_INFO
if number of rows is too large for theint
data 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.SQLException
Executes 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:
executeLargeUpdate
in 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.SQLException
Executes 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:
execute
in 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.SQLException
Returns the last result set produces by this statement.- Specified by:
getResultSet
in interfacejava.sql.Statement
- Returns:
- the result set
- Throws:
java.sql.SQLException
-
getUpdateCount
public final int getUpdateCount() throws java.sql.SQLException
Returns the last update count of this statement.- Specified by:
getUpdateCount
in 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_INFO
if number of rows is too large for theint
data type) - Throws:
java.sql.SQLException
- if this object is closed or invalid- See Also:
getLargeUpdateCount()
-
getLargeUpdateCount
public final long getLargeUpdateCount() throws java.sql.SQLException
Returns the last update count of this statement.- Specified by:
getLargeUpdateCount
in 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.SQLException
Closes this statement. All result sets that where created by this statement become invalid after calling this method.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in 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:
getConnection
in interfacejava.sql.Statement
- Returns:
- the connection
-
getWarnings
public java.sql.SQLWarning getWarnings() throws java.sql.SQLException
Gets the first warning reported by calls on this object. This driver does not support warnings, and will always return null.- Specified by:
getWarnings
in interfacejava.sql.Statement
- Returns:
- null
- Throws:
java.sql.SQLException
-
clearWarnings
public void clearWarnings() throws java.sql.SQLException
Clears all warnings. As this driver does not support warnings, this call is ignored.- Specified by:
clearWarnings
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
setCursorName
public void setCursorName(java.lang.String name) throws java.sql.SQLException
Sets the name of the cursor. This call is ignored.- Specified by:
setCursorName
in interfacejava.sql.Statement
- Parameters:
name
- ignored- Throws:
java.sql.SQLException
- if this object is closed
-
setFetchDirection
public void setFetchDirection(int direction) throws java.sql.SQLException
Sets the fetch direction. This call is ignored by this driver.- Specified by:
setFetchDirection
in interfacejava.sql.Statement
- Parameters:
direction
- ignored- Throws:
java.sql.SQLException
- if this object is closed
-
getFetchDirection
public int getFetchDirection() throws java.sql.SQLException
Gets the fetch direction.- Specified by:
getFetchDirection
in interfacejava.sql.Statement
- Returns:
- FETCH_FORWARD
- Throws:
java.sql.SQLException
- if this object is closed
-
getMaxRows
public int getMaxRows() throws java.sql.SQLException
Gets the maximum number of rows for a ResultSet.- Specified by:
getMaxRows
in 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.SQLException
Gets the maximum number of rows for a ResultSet.- Specified by:
getLargeMaxRows
in 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.SQLException
Gets the maximum number of rows for a ResultSet.- Specified by:
setMaxRows
in 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.SQLException
Gets the maximum number of rows for a ResultSet.- Specified by:
setLargeMaxRows
in 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.SQLException
Sets 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:
setFetchSize
in 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.SQLException
Gets the number of rows suggested to read in one step.- Specified by:
getFetchSize
in interfacejava.sql.Statement
- Returns:
- the current fetch size
- Throws:
java.sql.SQLException
- if this object is closed
-
getResultSetConcurrency
public int getResultSetConcurrency() throws java.sql.SQLException
Gets the result set concurrency created by this object.- Specified by:
getResultSetConcurrency
in interfacejava.sql.Statement
- Returns:
- the concurrency
- Throws:
java.sql.SQLException
-
getResultSetType
public int getResultSetType() throws java.sql.SQLException
Gets the result set type.- Specified by:
getResultSetType
in interfacejava.sql.Statement
- Returns:
- the type
- Throws:
java.sql.SQLException
- if this object is closed
-
getMaxFieldSize
public int getMaxFieldSize() throws java.sql.SQLException
Gets the maximum number of bytes for a result set column.- Specified by:
getMaxFieldSize
in 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.SQLException
Sets the maximum number of bytes for a result set column. This method does currently do nothing for this driver.- Specified by:
setMaxFieldSize
in 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.SQLException
Enables or disables processing or JDBC escape syntax. See also Connection.nativeSQL.- Specified by:
setEscapeProcessing
in 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.SQLException
Cancels 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:
cancel
in 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.SQLException
Gets 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:
getQueryTimeout
in 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.SQLException
Sets 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:
setQueryTimeout
in 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.SQLException
Adds a statement to the batch.- Specified by:
addBatch
in interfacejava.sql.Statement
- Parameters:
sql
- the SQL statement- Throws:
java.sql.SQLException
-
clearBatch
public void clearBatch() throws java.sql.SQLException
Clears the batch.- Specified by:
clearBatch
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
-
executeBatch
public int[] executeBatch() throws java.sql.SQLException
Executes the batch. If one of the batched statements fails, this database will continue.- Specified by:
executeBatch
in interfacejava.sql.Statement
- Returns:
- the array of update counts
- Throws:
java.sql.SQLException
- See Also:
executeLargeBatch()
-
executeLargeBatch
public long[] executeLargeBatch() throws java.sql.SQLException
Executes the batch. If one of the batched statements fails, this database will continue.- Specified by:
executeLargeBatch
in 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.SQLException
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.Generated keys are only returned from from
INSERT
,UPDATE
,MERGE INTO
, andMERGE 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:- Columns with sequences including
IDENTITY
columns 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:
getGeneratedKeys
in 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.SQLException
Moves 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:
getMoreResults
in interfacejava.sql.Statement
- Returns:
- false
- Throws:
java.sql.SQLException
- if this object is closed.
-
getMoreResults
public boolean getMoreResults(int current) throws java.sql.SQLException
Move to the next result set. This method always returns false.- Specified by:
getMoreResults
in 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.SQLException
Executes a statement and returns the update count. This method is not allowed for prepared statements.- Specified by:
executeUpdate
in interfacejava.sql.Statement
- Parameters:
sql
- 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 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_INFO
if number of rows is too large for theint
data 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.SQLException
Executes a statement and returns the update count. This method is not allowed for prepared statements.- Specified by:
executeLargeUpdate
in interfacejava.sql.Statement
- Parameters:
sql
- 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 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.SQLException
Executes a statement and returns the update count. This method is not allowed for prepared statements.- Specified by:
executeUpdate
in 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_INFO
if number of rows is too large for theint
data 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.SQLException
Executes a statement and returns the update count. This method is not allowed for prepared statements.- Specified by:
executeLargeUpdate
in 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.SQLException
Executes a statement and returns the update count. This method is not allowed for prepared statements.- Specified by:
executeUpdate
in 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_INFO
if number of rows is too large for theint
data 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.SQLException
Executes a statement and returns the update count. This method is not allowed for prepared statements.- Specified by:
executeLargeUpdate
in 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.SQLException
Executes a statement and returns type of its result. This method is not allowed for prepared statements.- Specified by:
execute
in interfacejava.sql.Statement
- Parameters:
sql
- 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 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.SQLException
Executes a statement and returns type of its result. This method is not allowed for prepared statements.- Specified by:
execute
in 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.SQLException
Executes a statement and returns type of its result. This method is not allowed for prepared statements.- Specified by:
execute
in 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.SQLException
Gets the result set holdability.- Specified by:
getResultSetHoldability
in interfacejava.sql.Statement
- Returns:
- the holdability
- Throws:
java.sql.SQLException
-
closeOnCompletion
public void closeOnCompletion() throws java.sql.SQLException
Specifies that this statement will be closed when its dependent result set is closed.- Specified by:
closeOnCompletion
in interfacejava.sql.Statement
- Throws:
java.sql.SQLException
- if this statement is closed
-
isCloseOnCompletion
public boolean isCloseOnCompletion() throws java.sql.SQLException
Returns whether this statement will be closed when its dependent result set is closed.- Specified by:
isCloseOnCompletion
in interfacejava.sql.Statement
- Returns:
true
if 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.SQLException
Returns whether this statement is closed.- Specified by:
isClosed
in 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.SQLException
Return an object of this class if possible.- Specified by:
unwrap
in interfacejava.sql.Wrapper
- Parameters:
iface
- the class- Returns:
- this
- Throws:
java.sql.SQLException
-
isWrapperFor
public boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException
Checks if unwrap can return an object of this class.- Specified by:
isWrapperFor
in 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:
isPoolable
in 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:
setPoolable
in interfacejava.sql.Statement
- Parameters:
poolable
- the requested value
-
enquoteIdentifier
public java.lang.String enquoteIdentifier(java.lang.String identifier, boolean alwaysQuote) throws java.sql.SQLException
Description copied from interface:JdbcStatementBackwardsCompat
Enquotes the specified identifier.- Specified by:
enquoteIdentifier
in interfaceJdbcStatementBackwardsCompat
- Specified by:
enquoteIdentifier
in interfacejava.sql.Statement
- Parameters:
identifier
- identifier to quote if required, may be quoted or unquotedalwaysQuote
- iftrue
identifier will be quoted unconditionally- Returns:
- specified identifier quoted if required, explicitly requested, or if it was already quoted
- Throws:
java.lang.NullPointerException
- if identifier isnull
java.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.SQLException
Description copied from interface:JdbcStatementBackwardsCompat
Checks if specified identifier may be used without quotes.- Specified by:
isSimpleIdentifier
in interfaceJdbcStatementBackwardsCompat
- Specified by:
isSimpleIdentifier
in interfacejava.sql.Statement
- Parameters:
identifier
- identifier to check- Returns:
- is specified identifier may be used without quotes
- Throws:
java.lang.NullPointerException
- if identifier isnull
java.sql.SQLException
- on failure
-
toString
public java.lang.String toString()
INTERNAL- Overrides:
toString
in classjava.lang.Object
-
-