NonStop Server for Java (NSJ) Programmer's Guide (NSJ 2.0+)

Note: Previous versions of NSJ used an equal sign (=) instead of a plus sign. For compatibility, NSJ 1.6 supports
the equal sign, but the plus sign is recommended for new programs.
If the put() calls for the previous step are in a separate file, use the properties.load method to load that
file into the java.util.Properties object.
3.
Connect your program to the database, passing the java.util.Properties object to
DriverManager.getConnection().
4.
In SQL statements that require a property to alias an SQL name, use the aliases instead of their Guardian
filenames. Do not include the plus sign (+) prefixes in the SQL statements.
5.
Specifying Properties Using the put() Method
The following example creates and uses two aliases: longname1, for the Guardian filename $VOL1.MYVOL.MYTAB,
and longname2, for the Guardian filename $VOL1.MYVOL.MYTAB2. The put() calls that create the aliases are in
the program, not in a separate file.
// Create a java.util.Properties object named prop
java.util.Properties prop=new java.util.Properties();
// Create the alias longname1 for the Guardian filename $VOL1.MYVOL.MYTAB
prop.put("+longname1", "$VOL1.MYVOL.MYTAB");
// Create the alias longname2 for the Guardian filename $VOL1.MYVOL.MYTAB2
prop.put("+longname2", "$VOL1.MYVOL.MYTAB2");
// Connect the program to the database, passing prop
conn = DriverManager.getConnection("jdbc:sqlmp:", prop);
// Create an SQL statement
stmt = conn.createStatement();
// Use the aliases instead of their Guardian filenames
rslt = stmt.executeQuery("select * from longname1 where col1='pickme'");
rslt = stmt.executeQuery("select * from longname2 where col1='pickme'");
Specifying Properties in a Properties File
The following program has the same effect as the preceding program, except that the properties are in the file
jdbc-properties. The file jdbc-properties contains the following lines:
+longname1,$VOL1.MYVOL.MYTAB
+longname2,$VOL1.MYVOL.MYTAB2
To use this file within your program, you can either (a) create a properties object and load the file within your program
or (b) provide a System property called jdbcPropfile to tell JDBC the name of your properties file.
Loading a Properties File Programmatically
The following sample code loads a properties file:
// Create a java.util.Properties object named prop
java.util.Properties prop=new java.util.Properties();
// Load the file that creates the aliases
prop.load("jdbc-properties");