Updated on 2025-05-29 GMT+08:00

java.sql.Statement

java.sql.Statement is an SQL statement API.

Table 1 Support status for java.sql.Statement

Method Name

Return Type

Support JDBC4 (Yes/No)

Support Unplanned ALT (Yes/No)

addBatch(String sql)

void

Yes

Yes

clearBatch()

void

Yes

Yes

clearWarnings()

void

Yes

Yes

close()

void

Yes

Yes

closeOnCompletion()

void

Yes

Yes

execute(String sql)

boolean

Yes

Yes

execute(String sql, int autoGeneratedKeys)

boolean

Yes

Yes

execute(String sql, int[] columnIndexes)

boolean

Yes

Yes

execute(String sql, String[] columnNames)

boolean

Yes

Yes

executeBatch()

boolean

Yes

Yes

executeQuery(String sql)

ResultSet

Yes

Yes

executeUpdate(String sql)

int

Yes

Yes

executeUpdate(String sql, int autoGeneratedKeys)

int

Yes

Yes

executeUpdate(String sql, int[] columnIndexes)

int

Yes

Yes

executeUpdate(String sql, String[] columnNames)

int

Yes

Yes

getConnection()

Connection

Yes

Yes

getFetchDirection()

int

Yes

Yes

getFetchSize()

int

Yes

Yes

getGeneratedKeys()

ResultSet

Yes

Yes

getMaxFieldSize()

int

Yes

Yes

getMaxRows()

int

Yes

Yes

getMoreResults()

boolean

Yes

Yes

getMoreResults(int current)

boolean

Yes

Yes

getResultSet()

ResultSet

Yes

Yes

getResultSetConcurrency()

int

Yes

Yes

getResultSetHoldability()

int

Yes

Yes

getResultSetType()

int

Yes

Yes

getQueryTimeout()

int

Yes

Yes

getUpdateCount()

int

Yes

Yes

getWarnings()

SQLWarning

Yes

Yes

isClosed()

boolean

Yes

Yes

isCloseOnCompletion()

boolean

Yes

Yes

isPoolable()

boolean

Yes

Yes

setCursorName(String name)

void

Yes

Yes

setEscapeProcessing(boolean enable)

void

Yes

Yes

setFetchDirection(int direction)

void

Yes

Yes

setMaxFieldSize(int max)

void

Yes

Yes

setMaxRows(int max)

void

Yes

Yes

setPoolable(boolean poolable)

void

Yes

Yes

setQueryTimeout(int seconds)

void

Yes

Yes

setFetchSize(int rows)

void

Yes

Yes

cancel()

void

Yes

Yes

executeLargeUpdate(String sql)

long

No

Yes

getLargeUpdateCount()

long

No

Yes

executeLargeBatch()

long

No

Yes

executeLargeUpdate(String sql, int autoGeneratedKeys)

long

No

Yes

executeLargeUpdate(String sql, int[] columnIndexes)

long

No

Yes

executeLargeUpdate(String sql, String[] columnNames)

long

No

Yes

enableStreamingResults()

void

Yes

Yes

  • Using setFetchSize can reduce the memory occupied by result sets on the client. Result sets are packaged into cursors and segmented for processing, which will increase the communication traffic between the database and the client, affecting performance.
  • Database cursors are valid only within their transactions. If setFetchSize is set, you need to set the connection to the non-autocommit mode by setting setAutoCommit(false). In addition, you need to commit transactions on the connection to flush service data to a database.
  • The LargeUpdate method can only be used in JDBC 4.2 or later.
  • enableStreamingResults() is a customized API for enabling streaming read. This API indirectly calls setFetchSize(Integer.MIN_VALUE). To enable the streaming read function, set enableStreamingQuery in the URL to true and call setFetchSize(Integer.MIN_VALUE) or enableStreamingResults(). Except that the streaming read function is enabled, the input parameter of setFetchSize() can only be a positive number or 0.
  • When the transaction is committed in autocommit mode, if batchMode is set to OFF on the JDBC driver side before executeBatch is executed, executing executeBatch will expand the entire batch as an independent transaction for execution, which is equivalent to that the batch statement containing commit or abort. ALT replay is not supported after execution.