skip to main content
JDBC Connection Pool Manager : Creating a Data Source : Creating a DataDirect OpenAccess SDK Data Source Object
 

Creating a DataDirect OpenAccess SDK Data Source Object

The following example shows how to create a DataSource object and register it to a JNDI naming service. The DataSource class is provided by your JDBC Client and is database-independent. In the following example we use Oracle, so the DataSource class is OpenAccessDataSource. See Using the JDBC Client for the name of the DataSource class.
If you want the client application to use non-pooled connections (see Connecting to a Data Source), you must modify this example so that the JNDI entry is registered using the name jdbc/SparkyOracle.
If you want the client application to use pooled connections, the JNDI entry must map to the DataSource of the DataDirect Connection Pool Manager. Therefore, you must register two data sources:
The Connection Pool Manager's Data Source using the example in Creating a Data Source Using the DataDirect Connection Pool Manager. This process registers the data source using the JNDI entry jdbc/SparkyOracle. The Connection Pool Manager will create physical connections using the JNDI Entry jdbc/OpenAccessSparkyOracle.
An OpenAccess SDK DataSource, using the following example to register the DataSource using the JNDI entry jdbc/OpenAccessSparkyOracle.
//***************************************************************
//
// This code creates an OpenAccess SDK for JDBC data source and registers it to a
// JNDI naming service. This data source uses the DataSource implementation
// provided by the JDBC Client.
//
// If you want users to use non-pooled connections, you must modify this
// example so that it registers the OpenAccess Data Source using the JNDI
// entry <jdbc/SparkyOracle>.
//
// If you want users to use pooled connections, use this example as is
// to register the OpenAccess Data Source using the JNDI entry
// <jdbc/OpenAccessSparkyOracle>. Also, use the example in the next section
// to register the Connection Pool Manager's Data Source using the JNDI entry
// <jdbc/SparkyOracle>
//
//************************************************************************
 
// From OpenAccess for JDBC:
import com.ddtek.jdbcx.OpenAccess.OpenAccessDataSource;
 
import javax.sql.*;
import java.sql.*;
import javax.naming.*;
import javax.naming.directory.*;
import java.util.Hashtable;
 
public class OpenAccessDataSourceRegisterJNDI
{
public static void main(String argv[])
{
try {
// Set up data source reference data for naming context:
// ----------------------------------------------------
// Create a class instance that implements the interface
// ConnectionPoolDataSource
OracleDataSource ds = new OpenAccessDataSource();
 
ds.setDescription(
"OpenAccess Data Source");
ds.setServerName("sparky");
ds.setPortNumber(19996);
ds.setUser("scott");
ds.setPassword("test");
 
// Set up environment for creating initial context
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");
env.put(Context.PROVIDER_URL, "file:c:\\JDBCDataSource");
Context ctx = new InitialContext(env);
 
// Register the data source to JNDI naming service
ctx.bind("jdbc/OpenAccessSparkyOracle", ds);
 
} catch (Exception e) {
System.out.println(e);
Sreturn;
}
} // Main
} // class OpenAccessDataSourceRegisterJNDI