SQL/MX Programming Manual for Java
Sample Programs
HP NonStop SQL/MX Programming Manual for Java—523726-003
C-19
StreamParcels.sqlj—Stream Access Mode
StreamParcels.sqlj—Stream Access Mode
In this SQLJ program, an iterator with the holdability property accesses a regular 
database table as a continuous data stream. The iterator remains open when the 
transaction is committed and when a new transaction is started after each row is 
fetched.
The stream access mode first does a regular scan of the table. Then, if all available 
rows have been retrieved, the stream access mode causes the fetch operation to block 
(wait) until more rows are available instead of returning the end-of-data condition. 
The stream timeout setting controls the time that the fetch operation waits for a row to 
be available. Because this program does not set the stream timeout value, it uses the 
default stream timeout value, which causes the stream to wait indefinitely to return 
rows from the table.
For information about publish/subscribe functionality, see the SQL/MX Queuing and 
Publish/Subscribe Services manual.
This SQLJ program uses tables in the shipping database. To install this database, see 
the SQL/MX Quick Start. 
SQLJ Source File
Example C-5. StreamParcels.sqlj—Stream Access Mode (page 1 of 2)
import java.sql.*;
#sql iterator StreamHoldIter with (holdability=true)
 (int, int, int);
public class StreamParcels
{
 public static void main(String[] args)
 {
 int destination = 0;
 int origin = 0;
 int seqnbr = 0;
 StreamHoldIter arrivals = null;
 try
 {
 #sql { MODULE psdb.pubs.streamparcelsmod };
 #sql { BEGIN WORK }; /* Start a transaction */
 // Use an iterator to fetch parcels from a stream
 #sql arrivals = { SELECT destination, origin, seqnbr
 FROM STREAM(psdb.pubs.inbox) };










