java.sql.Statement

2026-02-05 08:35:20  Updated

java.sql.Statement is an SQL statement interface.

Description

java.sql.Statement is used for executing a static SQL statement and returning the execution results.

By default, only one ResultSet object can be opened for each Statement object at a given time. Therefore, only ResultSet objects generated by different Statement objects can be read in an interleaved manner. If an open ResultSet object exists, all execution methods in the Statement interface implicitly close the current ResultSet object of the statement.

Methods

Method Return type Description Supported in Oracle mode Supported in MySQL mode
executeQuery(String sql) ResultSet Executes an SQL query that returns a single ResultSet object. Yes Yes
executeUpdate(String sql) int Executes an INSERT, UPDATE, or DELETE statement and returns the number of affected rows. Yes Yes
close() void Closes a Statement object and releases its resources. Yes Yes
getMaxFieldSize() int Obtains the maximum column size of a result set. Yes Yes
setMaxFieldSize(int max) void Sets the maximum column size of a result set. Yes Yes
getMaxRows() int Obtains the maximum number of rows that can be contained in any ResultSet object produced by a Statement object. Yes Yes
setMaxRows(int max) void Sets the maximum number of rows that can be contained in any ResultSet object produced by a Statement object. Yes. This parameter takes effect in OceanBase Connector/J V2.4.11 and later. Yes
setEscapeProcessing(boolean enable) void Specifies whether to enable SQL escape processing. Yes Yes
getQueryTimeout() int Obtains the query timeout period, in seconds. Yes Yes
setQueryTimeout(int seconds) void Sets the query timeout period, in seconds. Yes Yes
cancel() void Cancels the current execution of a Statement object. Yes Yes
getWarnings() SQLWarning Obtains the warnings generated during the execution of a Statement object. Yes Yes
clearWarnings() void Clears all warnings generated on a Statement object. Yes Yes
setCursorName(String name) void Sets the cursor name of a ResultSet object. This method is not supported in either MySQL or Oracle mode. No No
getResultSet() ResultSet Obtains the current ResultSet object. Yes Yes
getUpdateCount() int Obtains the number of rows affected by an update operation. Yes Yes
getMoreResults() Boolean Moves to the next result. Yes Yes
setFetchDirection(int direction) void Sets the fetch direction of a ResultSet object. This method is not supported in either MySQL or Oracle mode. No No
getFetchDirection() int Obtains the fetch direction of a ResultSet object. Yes Yes
setFetchSize(int rows) void Sets the fetch size (number of rows) of a Statement object. Yes Yes
getFetchSize() int Obtains the fetch size of a Statement object. Yes Yes
getResultSetConcurrency() int Obtains the concurrency mode of a ResultSet object. Yes Yes
getResultSetType() int Obtains the type of a ResultSet object. Yes Yes
addBatch(String sql) void Adds an SQL command to the list of commands that will be executed as a batch. Yes Yes
clearBatch() void Clears the list of commands that will be executed as a batch. Yes Yes
executeBatch() int[] Executes a batch of commands and returns an array of update counts. Yes Yes
getConnection() Connection Obtains the Connection object that produced this Statement object. Yes Yes
getGeneratedKeys() ResultSet Obtains the auto-generated keys created after an INSERT statement is executed. If the configuration compatibleOjdbcVersion=8&useArrayBinding=true&useOraclePrepareExecute=true is specified in Oracle mode, the RETURNING...INTO.. clause can be used to implement the getGeneratedKeys() method for obtaining the batch operation result set. Yes Yes
execute(String sql, int autoGeneratedKeys) Boolean Executes a given SQL statement, and instructs the driver whether to make any auto-generated keys available for retrieval. Yes Yes
execute(String sql, int columnIndexes[]) Boolean Executes a given SQL statement, and instructs the driver whether to make only the auto-generated keys corresponding to columns specified in the columnIndexes[] array available for retrieval. Yes Yes
execute(String sql, String columnNames[]) Boolean Executes the given SQL statement, and instructs the driver whether to make only the auto-generated keys corresponding to columns specified in the columnNames[] array available for retrieval. Yes Yes
getResultSetHoldability() int Obtains the holdability of a ResultSet object. Yes Yes
isClosed() Boolean Verifies whether a Statement object has been closed. Yes Yes
setPoolable(boolean poolable) void Specifies whether the application can pool a Statement object. No No
isPoolable() Boolean Verifies whether a Statement object is poolable. Yes Yes
closeOnCompletion() void Specifies to close a Statement object when all its dependent ResultSet objects are closed. Yes Yes
isCloseOnCompletion() Boolean Verifies whether a Statement object will be closed when all its dependent ResultSet objects are closed. Yes Yes
getLargeUpdateCount() long Obtains the number of rows affected by an update operation. This method is used when the returned row count is large. Yes Yes
setLargeMaxRows(long max) void Sets the maximum number of rows that can be contained in any ResultSet object produced by a Statement object. This method is used when the row limit is large. Yes Yes
getLargeMaxRows() long Obtains the maximum number of rows that can be contained in any ResultSet object produced by a Statement object. This method is used when the returned row limit is large. Yes Yes
executeLargeBatch() long[] Executes a batch of commands and returns an array of update counts. This method is used when the returned row count is large. Yes Yes
executeLargeUpdate(String sql) long Executes a given SQL statement. This method is applicable to update operations and is used when the returned row count is large. Yes Yes
executeLargeUpdate(String sql, int autoGeneratedKeys) long Executes a given SQL statement and instructs the driver whether to make any auto-generated keys available for retrieval. This method is used when the returned row count is large. Yes Yes
executeLargeUpdate(String sql, int columnIndexes[]) long Executes a given SQL statement and instructs the driver whether to make only the auto-generated keys corresponding to the columns specified in the columnIndexes[] array available for retrieval. This method is used when the returned row count is large. Yes Yes
executeLargeUpdate(String sql,String columnNames[]) long Executes a given SQL statement and instructs the driver whether to make only the auto-generated keys corresponding to the columns specified in the columnNames[] array available for retrieval. This method is used when the returned row count is large. Yes Yes

Contact Us