Rowids In Sqlj With The Ibm Data Server Driver For Jdbc And Sqlj - IBM DB2 Manual

Table of Contents

Advertisement

ROWIDs in SQLJ with the IBM Data Server Driver for JDBC
and SQLJ
|
|
|
DB2 for z/OS and DB2 for i5/OS support the ROWID data type for a column in a
table. A ROWID is a value that uniquely identifies a row in a table.
Although IBM Informix Dynamic Server (IDS) also supports rowids, those rowids
have the INTEGER data type. You can select an IDS rowid column into a variable
with a four-byte integer data type.
If you use columns with the ROWID data type in SQLJ programs, you need to
customize those programs.
JDBC 4.0 includes interface java.sql.RowId that you can use in iterators and in
CALL statement parameters. If you do not have JDBC 4.0, you can use the IBM
Data Server Driver for JDBC and SQLJ-only class com.ibm.db2.jcc.DB2RowID. For
an iterator, you can also use the byte[] object type to retrieve ROWID values.
The following code shows an example of an iterator that is used to select values
from a ROWID column:
#sql iterator PosIter(int,String,java.sql.RowId);
{
PosIter positrowid;
java.sql.RowId rowid = null;
int id = 0;
String i_fmt = null;
#sql [ctxt] positrowid =
{SELECT ITEM_ID, ITEM_FORMAT, ITEM_ROWID FROM ROWIDTAB
WHERE ITEM_ID=3};
#sql {FETCH :positrowid INTO :id, :i_fmt, :rowid};
while (!positrowid.endFetch())
{System.out.println("Item ID " + id + " Item format " +
i_fmt + " Item ROWID ");
printBytes(rowid.getBytes());
#sql {FETCH :positrowid INTO :id, :i_fmt, :rowid};
}
positrowid.close();
}
Figure 48. Example of using an iterator to retrieve ROWID values
The following code shows an example of calling a stored procedure that takes
three ROWID parameters: an IN parameter, an OUT parameter, and an INOUT
parameter.
// Declare positioned iterator
// for retrieving ITEM_ID (INTEGER),
// ITEM_FORMAT (VARCHAR), and ITEM_ROWID (ROWID)
// values from table ROWIDTAB
// Declare object of PosIter class
// Declare host expressions
// Assign the result table of the SELECT
// to iterator object positrowid
// Retrieve the first row
// Check whether the FETCH returned a row
// Use the getBytes method to
// convert the value to bytes for printing
// Retrieve the next row
// Close the iterator
Chapter 4. SQLJ application programming
143

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents