Nonstop Database, HiRDB Version 9 UAP Development Guide
The Statement interface provides the following principal functions:
The table below lists the methods of the Statement interface. This interface does not support methods that are not listed in the table. If an unsupported method is specified, the interface throws an SQLException.
Table 18-17 Statement interface methods
Subsection | Method | Function |
---|---|---|
(a) | addBatch(String sql) | Adds specified SQL statements to this Statement object's batch. |
(b) | cancel() | Cancels the SQL statements executing in the corresponding object and in objects using the same connection as the corresponding object. |
(c) | clearBatch() | Clears all SQL statements registered in this Statement object's batch. |
(d) | clearWarnings() | Clears all warnings that have been reported for this Statement object. |
(e) | close() | Closes the Statement object and any ResultSet object created from this Statement object. |
(f) | execute(String sql) | Executes a specified SQL statement. |
(g) | executeBatch() | Executes the SQL statements registered in a batch and returns an array of the numbers of updated rows. |
(h) | executeQuery(String sql) | Executes a specified retrieval SQL statement and returns a ResultSet object as the result. |
(i) | executeUpdate(String sql) | Executes a specified non-retrieval SQL statement and returns the number of updated rows. |
(j) | getConnection() | Returns the Connection object that created this Statement object. |
(k) | getFetchDirection() | Acquires the default fetch direction for a result set that is created from this Statement object. |
(l) | getFetchSize() | Acquires the default fetch size for a ResultSet object that is created from this Statement object. |
(m) | getMaxFieldSize() | Acquires the maximum number of bytes for the character columns or binary columns of a ResultSet object that is created by this Statement object. |
(n) | getMaxRows() | Acquires the maximum number of rows that can be stored in a ResultSet object created by this Statement object. |
(o) | getMoreResults() | Moves to the next result set. |
(p) | getQueryTimeout() | Returns the SQL execution timeout value (in seconds). |
(q) | getResultSet() | Acquires the current results as a ResultSet object. |
(r) | getResultSetConcurrency() | Acquires the parallel processing mode for a ResultSet object that is created from this Statement object. |
(s) | getResultSetHoldability() | Acquires the holding facility for a ResultSet object that is created from this Statement object. |
(t) | getResultSetType() | Acquires the type of the result set of a ResultSet object that is created from this Statement object. |
(u) | getUpdateCount() | Returns the number of updated rows. |
(v) | getWarnings() | Acquires the first warning that is reported by a call related to this Statement object. |
(w) | setCursorName(String name) | This method ignores the specified value because the driver does not support positioned updating or deletion processing. |
(x) | setEscapeProcessing(boolean enable) | Enables or disables escape syntax analysis by this Statement object. |
(y) | setFetchDirection(int direction) | Specifies the default fetch direction for a result set that is created from this Statement object. |
(z) | setFetchSize(int rows) | Specifies the default fetch size for a ResultSet object that is created from this Statement object. |
(aa) | setMaxFieldSize(int max) | Sets a maximum number of bytes for each character column or binary column in a ResultSet object that is created from this Statement object. |
(ab) | setMaxRows(int max) | Specifies the maximum number of rows that can be stored in a ResultSet object that is created from this Statement object. |
(ac) | setQueryTimeout(int seconds) | Specifies an SQL execution timeout value (in seconds). |
public synchronized void addBatch(String sql) throws SQLException
public void cancel() throws SQLException
public synchronized void clearBatch() throws SQLException
public synchronized void clearWarnings() throws SQLException
public void close() throws SQLException
public synchronized boolean execute(String sql) throws SQLException
Table 18-18 Relationship between the executed SQL statement and the return values of Statement.getResultSet and Statement.getUpdateCount
Type of executed SQL statement | Return value of Statement.getResultSet | Return value of Statement.getUpdateCount | |
---|---|---|---|
HiRDB_for_Java_DAB_EXECUTESQL_NOCHK system property setting | |||
Other than TRUE | TRUE | ||
Retrieval SQL statement | ResultSet object obtained as the execution result | -1 | |
Non-retrieval SQL statement | null | ResultSet object of 0 columns | 0 or a greater value |
SQL execution resulting in an error | null | null | -1 |
public synchronized int[] executeBatch() throws SQLException
public synchronized ResultSet executeQuery(String sql) throws SQLException
Table 18-19 Return values of the executeQuery method and the Statement.getUpdateCount method that is executed after the executeQuery method
Executed SQL statement type | executeQuery method's return value | Statement.getUpdateCount method's return value | |
---|---|---|---|
Retrieval SQL statement | ResultSet object for the execution result | -1 | |
Non-retrieval SQL statement | INSERT, UPDATE, DELETE | ResultSet object containing no columns | Number of updated rows |
Other | ResultSet object containing no columns | 0 | |
SQL statement resulting in an error | -- | -1 |
public synchronized int executeUpdate(String sql) throws SQLException
Executed SQL statement type | HiRDB_for_Java_DAB_EXECUTESQL_NOCHK system property setting | ||
---|---|---|---|
Other than TRUE | TRUE | ||
Retrieval SQL statement | -- | -1 | |
Non-retrieval SQL statement | INSERT, UPDATE, DELETE | Number of updated rows | Number of updated rows |
Other | 0 | 0 |
Table 18-20 Return value of the Statement.getResultSet method that is executed after the executeUpdate method
Executed SQL statement type | Statement.getResultSet method's return value | |
---|---|---|
Retrieval SQL statement | ResultSet object for the execution result | |
Non-retrieval SQL statement | INSERT, UPDATE, DELETE | ResultSet object containing no columns |
Other | ResultSet object containing no columns | |
SQL statement resulting in an error | null |
public synchronized Connection getConnection() throws SQLException
public synchronized int getFetchDirection() throws SQLException
public synchronized int getFetchSize() throws SQLException
Table 18-21 Relationship between fetch size and return value
setFetchSize setting (m) | Return value |
---|---|
0 | 0 |
1 |
m |
public synchronized int getMaxFieldSize() throws SQLException
public synchronized int getMaxRows() throws SQLException
public synchronized boolean getMoreResults() throws SQLException
public synchronized int getQueryTimeout() throws SQLException
public synchronized ResultSet getResultSet() throws SQLException
public synchronized int getResultSetConcurrency() throws SQLException
public synchronized int getResultSetHoldability() throws SQLException
public synchronized int getResultSetType() throws SQLException
public synchronized int getUpdateCount() throws SQLException
Statement object's method execution status | Return value of getUpdateCount | |||
---|---|---|---|---|
executeXXX method has not been executed. | -1 | |||
executeXXX method has been executed. | getMoreResults method was executed after the last executeXXX method was executed. | -1 | ||
The last executeXXX method executed resulted in an error. | -1 | |||
executeBatch method was executed at the end. | -1 | |||
An executeXXX method other than executeBatch was executed at the end. | A retrieval SQL statement was executed at the end. | -1 | ||
A non-retrieval SQL statement was executed at the end. | INSERT, UPDATE, DELETE |
Number of updated rows | ||
Other | 0 |
public synchronized SQLWarning getWarnings() throws SQLException
public synchronized void setCursorName(String name) throws SQLException
public synchronized void setEscapeProcessing(boolean enable) throws SQLException
public synchronized void setFetchDirection(int direction) throws SQLException
public synchronized void setFetchSize(int rows) throws SQLException
Table 18-22 Setting and actual PDBLKF value that is used
setFetchSize setting (m) | Value of PDBLKF client environment definition (n) | PDBLKF value used by block transfer facility |
---|---|---|
0 | 1 |
n |
Not specified | Not specified | |
1 |
1 |
m |
Not specified | m |
public synchronized void setMaxFieldSize(int max) throws SQLException
public synchronized void setMaxRows(int max) throws SQLException
public synchronized void setQueryTimeout(int seconds) throws SQLException
The names of the package and class for installing this interface are as follows:
If the value 1 or greater is specified for the setFetchSize method, the JDBC driver uses the block transfer facility and requests the HiRDB server to transfer all at once the retrieval results for the number of rows specified in the argument. For details about the block transfer facility, see 4.7 Block transfer facility.
Although there is no maximum specification value for the setFetchSize method, the block transfer facility can transfer only up to 4,096 rows at a time. Therefore, when a value greater than 4,096 is specified, the number of rows actually transferred at once will not exceed 4,096.
The following table shows the priorities that determine the number of rows that the JDBC driver requests the HiRDB server to transfer in a single transmission.
Table 18-23 Priorities for number of rows that the JDBC driver requests the HiRDB server to transfer in one transmission
Priority | Specification value |
---|---|
1 | Value specified in the argument of the setFetchSize method of the ResultSet class |
2 | Value specified in the argument of the setFetchSize method of the Statement class |
3 | Value specified in the PDBLKF client environment definition |
For details about the number of rows that the JDBC driver actually receives from the HiRDB server in one communication when the driver requests the number of rows indicated in Table 18-23, see 4.7(4) Number of rows transferred in one transmission. However, when reading this section, replace PDBLKF with number of rows requested for transfer as determined by the priorities shown in Table 18-23, and replace FETCH statement with next method of the ResultSet class.
If the retrieval result is larger than the number of transfer rows shown in Table 18-23, the JDBC driver requests transfer to the HiRDB server as many times as necessary until retrieval is completed (or until all retrieval requests from the UAP are processed).
If one of the following conditions is satisfied, the number of rows that the JDBC driver receives from the HiRDB server in one transmission is 1:
You can use the cancel method to execute asynchronous cancellation of SQL statements being processed by the HiRDB server. Even if the target Statement object is not executing an SQL statement, asynchronous cancellation is executed if another object is executing an SQL statement for the same connected object.
When asynchronous cancellation is executed at the HiRDB server, all PreparedStatement and ResultSet objects that were created before the asynchronous cancellation become invalid, regardless of the specification for validating or invalidating Statement and ResultSet objects after commit execution.
The following methods specify whether or not objects are to remain valid after commit execution:
Asynchronous cancellation is not executed for the HiRDB server if the target Statement object is not executing an SQL statement, and if no other object is executing an SQL statement for that same connection object.
If XADataSource was used for the connection, an asynchronous cancellation request is not valid.
If you execute an executeXXX method before the ResultSet object created by the corresponding Statement object has been closed, the JDBC driver closes the previous ResultSet object that was created. If an attempt is made to use the previously created ResultSet object to acquire search results after the executeXXX method has been executed, the JDBC driver will throw an SQLException. The following shows an example that results in an SQLException:
Statement st = con.createStatement(); ResultSet rs1 = st.executeQuery("select * from tb1"); ResultSet rs2 = st.executeQuery("select * from tb2"); rs1.next(); // Throw SQLException rs2.next(); |
All Rights Reserved. Copyright (C) 2011, Hitachi, Ltd.