Updated on 2025-08-25 GMT+08:00

java.sql.Statement

java.sql.Statement is the SQL statement interface.

Table 1 Support for java.sql.Statement

Method

Return Type

JDBC 4 Support

close()

void

Yes

execute(String sql)

Boolean

Yes

executeQuery(String sql)

ResultSet

Yes

executeUpdate(String sql)

int

Yes

getConnection()

Connection

Yes

getResultSet()

ResultSet

Yes

getQueryTimeout()

int

Yes

getUpdateCount()

int

Yes

isClosed()

Boolean

Yes

setQueryTimeout(int seconds)

void

Yes

setFetchSize(int rows)

void

Yes

cancel()

void

Yes

By using setFetchSize, you can reduce the memory usage of the result set on the client. The principle behind this is that the result set is packaged into a cursor and then processed in segments, which increases the communication between the database and the client, leading to some performance overhead.

Since database cursors are valid within a transaction, when setting setFetchSize, you need to configure the connection to non-auto-commit mode by calling setAutoCommit(false). Additionally, when service data needs to be persisted to the database, a commit operation should be executed on the connection.