Hitachi

Hitachi Advanced Database Application Development Guide


8.3.8 execute(String sql)

Organization of this subsection

(1) Function

This method executes an SQL statement. You can use the getResultSet and getUpdateCount methods (or the getLargeUpdateCount method) to acquire the ResultSet object and the number of updated rows.

The following table shows the return values of the getResultSet and getUpdateCount methods (or the getLargeUpdateCount method) depending on the type of the SQL statement that was executed.

Table 8‒8: Return values of the getResultSet and getUpdateCount methods (or the getLargeUpdateCount method) depending on the type of the SQL statement that was executed

Type of the SQL statement that was executed

Return value of the getResultSet method

Return value of the getUpdateCount method or getLargeUpdateCount method

Retrieval SQL statement

ResultSet object obtained as the execution result

-1

Non-retrieval SQL statement

null

0 or a greater value#

SQL execution resulting in an error

null

-1

#

If the number of updated rows might exceed Integer.MAX_VALUE, use the getLargeUpdateCount method instead of the getUpdateCount method. If you use the getUpdateCount method, it will return 0 if the number of updated rows exceeds Integer.MAX_VALUE.

Note

A retrieval SQL statement means a SELECT statement. Non-retrieval SQL statements include update SQL statements (such as the UPDATE statement) and definition SQL statements (such as CREATE TABLE).

An update SQL statement means INSERT, UPDATE, DELETE, PURGE CHUNK, and TRUNCATE TABLE statements.

(2) Format

public synchronized boolean execute(String sql) throws SQLException

(3) Arguments

String sql

Specifies the SQL statement that is to be executed.

(4) Return value

If a retrieval SQL statement was executed, this method returns true; if not, the method returns false.

(5) Exceptions

The JDBC driver throws an SQLException in the following cases: