JDBC Type 4 Driver Programmer's Reference for SQL/MX Release 3.2 (H06.25+, J06.14+)
Connecting using the DriverManager Class
“Loading and Registering the Driver” (page 24)
“Establishing the Connection” (page 24)
“Guidelines for connecting with the Driver Manager” (page 25)
The java.sql.DriverManager class is widely used to get a connection, but is less portable
than the DataSource class. The DriverManager class works with the Driver interface to manage
the set of drivers loaded. When an application issues a request for a connection using the
DriverManager.getConnection method and provides a URL, the DriverManager finds a
suitable driver that recognizes this URL and obtains a database connection using that driver.
com.tandem.t4jdbc.SQLMXDriver is the Type 4 driver class that implements the
java.sql.Driver interface.
Loading and Registering the Driver
Before to the database, the application loads the Driver class and registers the Type 4 driver
with the DriverManager class in one of the following ways:
• Specifies the Type 4 driver class in the -Djdbc.drivers option in the command line of the
Java program:
-Djdbc.drivers=com.tandem.t4jdbc.SQLMXDriver
• Uses the Class.forName method programmatically within the application:
Class.forName("com.tandem.t4jdbc.SQLMXDriver")
• Adds the Type 4 driver class to the java.lang.System property jdbc.drivers property
within the application:
jdbc.drivers=com.tandem.t4jdbc.SQLMXDriver
Establishing the Connection
The DriverManager.getConnection method accepts a string containing a Type 4 driver URL.
The JDBC URL for the Type 4 driver is:
jdbc:t4sqlmx://ip_address|machine_name:port_number/[:][property=value [;property2=value2]...]
where
ip_address:port_number specifies the location where the NonStop MXCS association server
is running.
property=value and property2=value2; specify a Type 4 driver property name-property
value pair. The pairs must be separated by a semicolon (;). For example,
T4LogLevel=ALL;T4LogFile=temp1.log
For information about the properties file, see “Type 4 Driver Properties” (page 34).
To establish a connection, the JDBC application can use the following code:
Class.forName("com.tandem.t4jdbc.SQLMXDriver"); //loads the driver
String url = “jdbc:t4sqlmx://ip_address|machine_name:port_number/”
Connection con = DriverManager.getConnection(url, “userID”, “Passwd”);
The variable con represents a connection to the MXCS data source that can be used to create and
execute SQL statements.
24 Accessing SQL Databases with SQL/MX










