SQL/MX Programming Manual for Java
Sample Programs
HP NonStop SQL/MX Programming Manual for Java—523726-003
C-3
SQLJ Source File
 /* The following constructor instantiates connection context objects 
 * and establishes default database connections.
 * The try-catch block reports errors connecting to the database. */
 public SampleDDL() {
 try {
 ctx1 = DefConCtx1.getDefaultContext();
 ctx2 = DefConCtx2.getDefaultContext();
 ctx3 = DefConCtx3.getDefaultContext();
 #sql [ctx1] { MODULE samdbcat2.persnl2.ddlmod };
 #sql [ctx2] { MODULE samdbcat2.sales2.ddlmod };
 #sql [ctx3] { MODULE samdbcat2.invent2.ddlmod };
 } 
 catch (Exception exception) {
 System.err.println ("Error connecting to the database: " 
 + exception);
 }
 }
 // main() method
 public static void main (String [] args) {
 SampleDDL s1 = new SampleDDL();
 try {
 s1.doCATSCH(); // Invokes a method that creates catalogs 
 // and schemas
 s1.doTABLES(); // Invokes a method that creates tables
 s1.ctx1.close(); // Closes the connection for the ctx1 
 // connection context
 s1.ctx2.close(); // Closes the connection for the ctx2 
 // connection context
 s1.ctx3.close(); // Closes the connection for the ctx3 
 // connection context
 }
 // Throw an SQL exception if an error occurs during execution
 catch (SQLException e) {
 System.err.println ("Exception: " + e);
 }
 } // End of main() method
Example C-1. SampleDDL.sqlj—Creating Tables From an SQLJ 
Program (page 2 of 7)










