Query Methods for the Statement Object

To run a query embedded in a Statement object, you use variants of the execute method. Important variants of this method are listed in Table 4-1.

Table 4-1 Key Query Execution Methods for java.sql.Statement

Method Name Return Type Description

execute(String sql)

Boolean

Runs the given SQL statement, which returns a Boolean response: true if the query runs successfully and false if it does not.

addBatch()

void

Adds a set of parameters to a PreparedStatement object batch of commands.

executeBatch()

int[]

Submits a batch of commands to the database for running, and returns an array of update counts if all commands run successfully.

executeQuery(String sql)

ResultSet

Runs the given SQL statement, which returns a single ResultSet object.

executeUpdate(String sql)

int

Runs the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or a SQL statement that returns nothing, such as a SQL DDL statement.