8.2.37 setHADBSQLMaxRthdNum(int rthdNum)
- Organization of this subsection
(1) Function
This method sets for this Connection object the maximum number of SQL processing real threads.
The value set by this method is compatible with the adb_sql_exe_max_rthd_num operand in the client definition.
- Important
-
For the Statement or PreparedStatement object generated from the Connection object for which this method is specified, the maximum number of SQL processing real threads that is set by this method is applied until the Connection object is closed.
(2) Format
public void setHADBSQLMaxRthdNum(int rthdNum) throws SQLException
(3) Arguments
- int rthdNum
-
Specifies the maximum number of SQL processing real threads to be set.
(4) Return value
None.
(5) Exceptions
The JDBC driver throws an SQLException in the following cases:
-
The Connection object is closed.
-
An invalid value is specified in rthdNum.
(6) Notes
-
This is an HADB-specific method provided by the AdbConnection interface. For details about the execution method, see 12.2 Wrapper interface.
-
For the maximum number of SQL processing real threads specified by using the setHADBSQLMaxRthdNum method, the previously set value is not inherited if the Connection object is pooled and then reused. This is the same case as when the setHADBSQLMaxRthdNum method has not been executed.
-
Even if the setHADBSQLMaxRthdNum method is used to set the maximum number of SQL processing real threads again, the new setting is not applied to the Statement or PreparedStatement object that has already been generated.
-
For details about how the maximum number of SQL processing real threads is determined, see the explanation of the adb_sql_exe_max_rthd_num operand in 2.2.3 Operands related to performance.
(7) Examples
In the following example, the setHADBSQLMaxRthdNum and getHADBSQLMaxRthdNum methods are used to change the maximum number of SQL processing real threads for each SQL statement to be executed.
- Example 1:
-
: : Connection cnct = ds.getConnection(); AdbConnection con = cnct.unwrap(com.hitachi.hadb.jdbc.AdbConnection.class); // Back up the default of the maximum number of SQL processing real threads. int default_sql_exe_rthd_num = con.getHADBSQLMaxRthdNum(); // Change the maximum number of SQL processing real threads to 0. con.setHADBSQLMaxRthdNum(0); // Generate a PreparedStatement object. // All SQL statements executed with this PreparedStatement object operate under // the condition where the maximum number of SQL processing real threads is 0. PreparedStatement pstmt = con.prepareStatement("SELECT * FROM MASTER.SQL_USERS WHERE USER_NAME=?"); // Reset the maximum number of SQL processing real threads to the default. con.setHADBSQLMaxRthdNum(default_sql_exe_rthd_num); // This operation does not affect the preceding pstmt. pstmt.setString(1, "FOO"); ResultSet rs = pstmt.executeQuery(); // Execute an SQL statement under the // condition where the maximum number of SQL processing real threads is 0. while (rs.next()) { : : } rs.close(); pstmt.close(); : :
- Example 2:
-
In the following example, each SQL statement is executed with a different maximum number of SQL processing real threads.
: : Connection cnct = ds.getConnection(); AdbConnection con = cnct.unwrap(com.hitachi.hadb.jdbc.AdbConnection.class); // Back up the default of the maximum number of SQL processing real threads. int default_sql_exe_rthd_num = con.getHADBSQLMaxRthdNum(); // Change the maximum number of SQL processing real threads to 0. con.setHADBSQLMaxRthdNum(0); // Generate a PreparedStatement object. // All SQL statements executed with pstmt1 operate under the condition // where the maximum number of SQL processing real threads is 0. PreparedStatement pstmt1 = con.prepareStatement("SELECT * FROM MASTER.SQL_USERS WHERE USER_NAME=?"); // Change the maximum number of SQL processing real threads to 4. con.setHADBSQLMaxRthdNum(4); // This operation does not affect // the preceding pstmt1. // Generate a PreparedStatement object. // All SQL statements executed with pstmt2 operate under the condition // where the maximum number of SQL processing real threads is 4. PreparedStatement pstmt2 = con.prepareStatement("SELECT * FROM MASTER.SQL_TABLE_PRIVILEGES WHERE GRANTOR=?"); // Reset the maximum number of SQL processing real threads to the default. con.setHADBSQLMaxRthdNum(default_sql_exe_rthd_num); // This operation does not affect the preceding pstmt1 and pstmt2. pstmt1.setString(1, "HOGE"); ResultSet rs1 = pstmt1.executeQuery(); // Execute an SQL statement under the // condition where the maximum number of SQL processing real threads is 0. while (rs1.next()) { : : } rs1.close(); pstmt1.close(); pstmt2.setString(1, "FOO"); ResultSet rs2 = pstmt2.executeQuery(); // Execute an SQL statement under the // condition where the maximum number of SQL processing real threads is 4. while (rs2.next()) { : : } rs2.close(); pstmt2.close(); : :
- Note
-
-
In the preceding examples, the processing to handle exceptions and other errors is omitted.
-
The preceding examples will also be useful for reference purposes when you change the size of the hash table area for each SQL statement to be executed by using the setHADBSQLHashTblSize and getHADBSQLHashTblSize methods.
-
The preceding examples will also be useful for reference purposes when you change the size of the hash filter area for each SQL statement to be executed by using the setHADBSQLHashFltSize and getHADBSQLHashFltSize methods.
-