SQL/MX Programming Manual for Java
Sample Programs
HP NonStop SQL/MX Programming Manual for Java—523726-003
C-32
Translating the Program
Translating the Program
At an OSS prompt, enter this command to translate the SQLJ source file by running 
the SQLJ translator:
java sqlj.tools.Sqlj -createMDF SetOnRollback.sqlj
 // Wait for newly arrived parcels and notify receivers
 while (true)
 {
 try {
 #sql { FETCH :arrivals
 INTO :destination, :origin, :seqnbr };
 }
 catch (SQLException e)
 {
 // Continue after stream timeout error (-8006)
 // but handle other SQLExceptions in the outer 
 // try-catch block.
 if (e.getErrorCode() != -8006)
 throw e;
 }
 // Use the endFetch() method to see if a row was
 // returned. endFetch() returns false when the last
 // attempt to fetch a row succeeds. endFetch() 
 // returns true when the stream times out.
 if (arrivals.endFetch() == false)
 {
 System.out.println("Destination = " + destination);
 System.out.println("Origin = " + origin);
 System.out.println("Sequence number = " + seqnbr);
 System.out.println();
 }
 // Commit the transaction after each row is dequeued
 // or after a maximum of 5 seconds, which is the 
 // stream timeout setting. Start a new transaction 
 // and fetch again.
 #sql { COMMIT WORK };
 #sql { BEGIN WORK };
 } // end of infinite while loop
 }
 catch (SQLException e)
 {
 System.out.println("Sqlcode: " + e.getErrorCode());
 System.out.println("Message: " + e.getMessage());
 System.out.println("Sqlstate: " + e.getSQLState());
 }
 }
}
Example C-9. SetOnRollback.sqlj—Setting Column Values on 
Rollback (page2of2)










