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

java -Djdbc.drivers=com.tandem.sqlmp.SQLMPDriver;com.javaco.purejavajdbc.Driver
Adding the JDBC Driver Class to the jdbc.drivers Property
To add the JDBC driver class to the jdbc.drivers property:
Create a new Properties object using this command:
Properties prop=new Properties();
1.
Add the JDBC driver class to the jdbc.drivers property using this command:
prop.put("jdbc.drivers","driver_class_name[;driver_class_name]");
2.
Set the system properties using this command:
System.setProperties(prop);
3.
The first call to a JDBC DriverManager method loads the driver or drivers.
The following code adds the SQL/MP driver and the JDBC driver whose class name is
com.javaco.purejavajdbc.Driver to the jdbc.drivers property:
Properties prop=new Properties();
prop.put("jdbc.drivers","com.tandem.sqlmp.SQLMPDriver; \
> com.javaco.purejavajdbc.Driver");
System.setProperties(prop);
Loading the JDBC Driver Class Directly Into the JVM
To load the JDBC driver class directly into the JVM, use the Class.forName() method.
The following code loads the SQL/MP driver and the JDBC driver whose class name is
com.javaco.purejavajdbc.Driver directly into the JVM:
Class.forName("com.tandem.sqlmp.SQLMPDriver");
Class.forName("com.javaco.purejavajdbc.Driver");
Connecting a Program to a Database
After a driver is loaded, you can use it to connect your Java program to a database by passing the URL of the database to the
DriverManager.getConnection() method.
You do not need to specify a username and a password to connect to an SQL/MP database.
Standard Driver Example
In a Java program, the following code uses the standard driver, sqlmp, to create a connection (myConnection) between the
program and the local SQL/MP database:
import java.sql.*;
...
Connection myConnection = DriverManager.getConnection("jdbc:sqlmp:");
Note: You must specify the URL for the driver exactly as it is shown in this and the following examples.
Transaction-Aware Driver Example
In a Java program, the following code uses the transaction-aware driver, sqlmptx, to create a connection (myConnection)
between the program and the local SQL/MP database: