Updated on 2023-10-23 GMT+08:00

java.sql.Statement

This section describes java.sql.Statement, the interface for executing SQL statements.

Table 1 Support status for java.sql.Statement

Method Name

Return Type

JDBC 4 Is Supported Or Not

addBatch​(String sql)

void

Yes

clearBatch()

void

Yes

clearWarnings()

void

Yes

close()

void

Yes

closeOnCompletion()

void

Yes

execute(String sql)

Boolean

Yes

execute​(String sql, int autoGeneratedKeys)

Boolean

Yes

execute​(String sql, int[] columnIndexes)

Boolean

Yes

execute​(String sql, String[] columnNames)

Boolean

Yes

executeBatch()

Boolean

Yes

executeQuery(String sql)

ResultSet

Yes

executeUpdate(String sql)

int

Yes

executeUpdate​(String sql, int autoGeneratedKeys)

int

Yes

executeUpdate​(String sql, int[] columnIndexes)

int

Yes

executeUpdate​(String sql, String[] columnNames)

int

Yes

getConnection()

Connection

Yes

getFetchDirection()

int

Yes

getFetchSize()

int

Yes

getGeneratedKeys()

ResultSet

Yes

getMaxFieldSize()

int

Yes

getMaxRows()

int

Yes

getMoreResults()

boolean

Yes

getMoreResults​(int current)

boolean

Yes

getResultSet()

ResultSet

Yes

getResultSetConcurrency()

int

Yes

getResultSetHoldability()

int

Yes

getResultSetType()

int

Yes

getQueryTimeout()

int

Yes

getUpdateCount()

int

Yes

getWarnings()

SQLWarning

Yes

isClosed()

Boolean

Yes

isCloseOnCompletion()

Boolean

Yes

isPoolable()

Boolean

Yes

setCursorName​(String name)

void

Yes

setEscapeProcessing​(boolean enable)

void

Yes

setFetchDirection​(int direction)

void

Yes

setMaxFieldSize​(int max)

void

Yes

setMaxRows​(int max)

void

Yes

setPoolable​(boolean poolable)

void

Yes

setQueryTimeout(int seconds)

void

Yes

setFetchSize(int rows)

void

Yes

cancel()

void

Yes

executeLargeUpdate(String sql)

long

No

getLargeUpdateCount()

long

No

executeLargeBatch()

long

No

executeLargeUpdate(String sql, int autoGeneratedKeys)

long

No

executeLargeUpdate(String sql, int[] columnIndexes)

long

No

executeLargeUpdate(String sql, String[] columnNames)

long

No

  • 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, set setAutoCommit(false) and commit transactions on the connection to flush service data to a database.
  • LargeUpdate methods can only be used in JDBC 4.2 or later.