JDBC Type 4 Driver 1.1 Programmer's Reference

DataSource Object Properties
A DataSource object has properties that identify and describe the actual data source that the object represents. These
properties include such information as the URL for the MXCS association server, the database schema and catalog names, the
location of the database server, the name of the database, and so forth.
Note: When a JDBC application uses any server data source, the data source must be started before using it. Therefore, if
your application uses the default server data source, the server (MXCS) data source, ensure this data source is started
before attempting to make a connection. For more information, see the SQL/MX Connectivity Service Manual.
For details about Type 4 driver properties that you can use with the DataSource object, see the Type 4 Driver Properties
chapter.
Programmatically Creating an Instance of the DataSource Class
A JDBC application can set DataSource properties programmatically and register with a DataSource object.
To get or set DataSource object properties programmatically, use the appropriate getter or setter methods on the
SQLMXDataSource object or the SQLMXConnectionPoolDataSource object. For example,
SQLMXDataSource temp = new SQLMXDataSource(); temp.setCatalog("abc");
In the following example, the code fragment illustrates the methods that a DataSource object ds needs to include if the
object supports the property serverName.
ds.setServerName("my_database_server");
In the following example, the code shows setting properties for the SQLMXDataSource object to use the Type 4 driver to
access an SQL/MX database:
SQLMXDataSource ds = new SQLMXDataSource();
ds.setUrl("jdbc:t4sqlmx://mynode.mycompanynetwork.net:port_number/";
ds.setCatalog("mycat");
ds.setSchema("myschema");
ds.setUser("lee");
ds.setPassword("safeguard password");
// Properties relevant for Type 4 connection pooling.
// Set ds.setMaxPoolSize(-1) for turning OFF connection pooling
ds.setMaxPoolSize("10000");
ds.setMinPoolSize("1000");
// Properties relevant for Type 4 statement pooling.
// Set ds.setMaxStatement(0) for turning statement pooling OFF
// Statement pooling is enabled only when connection pooling is
// enabled.
ds.setMaxStatements("7000");
Programmatically Registering the DataSource Object
In the following example, the code shows how to register, programmatically, the SQLMXDataSource object ds that was
created using the preceding code with JDNI.
java.util.Hashtable env = new java.util.Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "Factory class name here");
javax.naming.Context ctx = new javax.naming.InitialContext(env);
ctx.rebind("myDataSource", ds);
Retrieving a DataSource Instance by using JNDI and to the Data Source
Typically, the JDBC application looks up the data source JNDI name from a context object. Once the application has the
DataSource object, the application does a getConnection() call on the data source and gets a connection.
The steps that JDBC application does to connect to and use the data source associated with the SQL/MX database are listed