Updated on 2024-08-20 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

JDBC4 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

enableStreamingResults()

void

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, set setAutoCommit(false) and 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.