JDBC Type 4 Driver 1.1 Programmer's Reference

below together with the application code to perform the operation.
Import the packages.
import javax.naming.*;
import java.sql.*;
import javax.sql.DataSource;
1.
Create the initial context.
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");
try
{
Context ctx = new InitialContext(env);
} catch( ... ) { ... }
2.
Look up the JNDI name associated with the data source myDataSource, where myDataSource is the logical name
that will be associated with the real world data source – MXCS server.
DataSource ds = (DataSource)ctx.lookup("myDataSource");
3.
Create the connection using the data source.
con = ds.getConnection();
4.
Do work with the connection. The following statements are just a simple example.
stmt = con.createStatement();
try
{
stmt.executeUpdate("drop table tdata");
}
catch (SQLException e) {}
5.
Specifying the Properties File that Configures the Data Source
To use the properties file method to configure a DataSource object, the properties file must exist on disk and contain the
property_name=property_value pairs that configure the data source. See Creating and Using a Properties File for
more information about creating this file.
When the JDBC application makes the connection, the application should pass the properties file as a command-line parameter:
java -Dt4sqlmx.properties=file_location ...
Connection by Using the DriverManager Class
Loading and Registering the Driver
Establishing the Connection
Guidelines for Connections Using the Driver Manager
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: