beautypg.com

Prepared statement, Batch operations – Sun Microsystems eWay JDBC/ODBC Adapter User Manual

Page 67

background image

Chapter 5

Section 5.2

Using JDBC/ODBC Operations

JDBC eWay Database Operations (JCD)

JDBC/ODBC eWay Adapter User’s Guide

67

Sun Microsytems, Inc.

parameters are retrieved. Therefore, you should retrieve all ResultSet(s) and Update
Counts first followed by retrieving the OUT type parameters and return values.

The following list includes specific ResultSet behavior that you may encounter:

ƒ

The method resultsAvailable() implicitly calls getMoreResults() when it is called
more than once. You should not call both methods in your java code. Doing so may
result in skipped data from one of the ResultSets when more than one ResultSet is
present.

ƒ

The methods available() and getResultSet() can not be used in conjunction with
multiple ResultSets being open at the same time. Attempting to open more the one
ResultSet at the same time closes the previous ResultSet. The recommended
working pattern is:

Š

Open one ResultSet (ResultSet_1) and work with the data until you have
completed your modifications and updates. Open ResultSet_2, (ResultSet_1 is
now closed) and modify. When you have completed your work in ResultSet_2,
open any additional ResultSets or close ResultSet_2.

ƒ

If you modify the ResultSet generated by the Execute mode of the Database Wizard,
you need to assure the indexes match the stored procedure. By doing this, your
ResultSet indexes are preserved.

ƒ

Generally, getMoreResults does not need to be called. It is needed if you do not
want to use our enhanced methods and you want to follow the traditional JDBC
calls on your own.

The DBWizard Assistant expects the column names to be in English when creating a
ResultSet.

Prepared Statement

A Prepared Statement OTD represents a SQL statement that has been compiled. Fields
in the OTD correspond to the input values that users need to provide.

Prepared statements can be used to perform insert, update, delete and query
operations. A prepared statement uses a question mark (?) as a place holder for input.
For example:

insert into EMP_TAB(Age, Name, Dept No) value(?, ?, ?)

To execute a prepared statement, set the input parameters and call executeUpdate() and
specify the input values if any.

getPrepStatement().getPreparedStatementTest().setAge(23);
getPrepStatement().getPreparedStatementTest().setName(‘Peter Pan’);
getPrepStatement().getPreparedStatementTest().setDeptNo(6);
getPrepStatement().getPreparedStatementTest().executeUpdate();

Batch Operations

To achieve better performance, consider using a bulk insert if you have to insert many
records. This is the “Add Batch” capability. The only modification required is to include
the addBatch() method for each SQL operation and then the executeBatch() call to