NonStop Server for Java (NSJ) Programmer's Guide (NSJ 2.0+)
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.
Original Driver Example
In a Java program, the following code uses the original 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:");
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:
import java.sql.*;
...
Connection myConnection = DriverManager.getConnection("jdbc:sqlmptx:");
Pure Java Driver Example
In a Java program, the following code uses a pure Java driver, javaco, to create a connection (myConnection)
between the program and the database MyDatabase, which resides on the server MyServer:
import java.sql.*;
...
Connection myConnection = \
> DriverManager.getConnection("jdbc:javaco://MyServer/MyDatabase");
Passing SQL/MP Statements to a Database
When you have a connection between your Java program and an SQL/MP database, you can create an SQL statement
and pass it to the database, which will return a result. To create an SQL statement, use the connection's
createStatement() method. To pass the statement to the database, use the statement's executeQuery()
method.
Each SQL statement runs as a waited operation, so executing an SQL statement within a thread blocks the JVM.
Note: If your SQL query includes the name of an SQL/MP table, fully qualify the table name in the query;
otherwise, the volume and subvolume of the table name will default to the current volume and subvolume.
In the following example, the result set is not cached, so each call to next() retrieves more information from the
database.