JDBC Driver for SQL/MP 3.0
Creating and Using Aliases
To create and use aliases:
1. Create a java.util.Properties object.
2. Put each alias-Guardian file-name pair (called a substitution property) in the java.util.Properties object.
Prefix each alias with a plus sign (+). The individual put() calls for this step can be either in your program.
Note: Previous versions of the NonStop Server for Java used an equal sign (=) instead of a plus sign. For
compatibility, the JDBC Driver for SQL/MP supports the equal sign, but HP recommends the plus sign for new
programs.
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 file
names. Do not include the plus sign (+) prefixes in the SQL statements.
Specifying Properties Using the put() Method
This example creates and uses two aliases: longname1, for the Guardian file name $VOL1.MYVOL.MYTAB, and
longname2, for the Guardian file name $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
This program has the same effect as the preceding program, except that the properties are in the file jdbc-properties.
The file jdbc-properties contains these 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
This sample code loads a properties file: