skip to main content
Using the Driver : Connection Pool Manager : Implementing DataDirect Connection Pooling : Creating a Driver Data Source Object
  

Try DataDirect Drivers Now
Creating a Driver Data Source Object
The following Java code example creates a Progress DataDirect data source object and registers it with a JNDI naming service.
Note: The DataSource class implements the ConnectionPoolDataSource interface for pooling in addition to the DataSource interface for non-pooling.
//************************************************************************
// This code creates a Progress DataDirect for JDBC data source and
// registers it to a JNDI naming service. This JDBC data source uses the
// DataSource implementation provided by Progress DataDirect for JDBC Drivers.
//
// This data source registers its name as <jdbc/ConnectCassandra>.
//// NOTE: To connect using a data source, the driver needs to access a JNDI data
// store to persist the data source information. To download the JNDI File
// System Service Provider, go to:
//
// http://www.oracle.com/technetwork/java/javasebusiness/downloads/
// java-archive-downloads-java-plat-419418.html#7110-jndi-1.2.1-oth-JPR
////
// Make sure that the fscontext.jar and providerutil.jar files from the
// download are on your classpath.
//************************************************************************
// From Progress DataDirect for JDBC:
import com.ddtek.jdbcx.cassandra.CassandraDataSource;
import javax.sql.*;
import java.sql.*;
import javax.naming.*;
import javax.naming.directory.*;
import java.util.Hashtable;
public class CassandraDataSourceRegisterJNDI
{   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
      CassandraDataSource ds = new CassandraDataSource();
      ds.setDescription("Cassandra Data Source");
      ds.setServerName("Server1");
      ds.setPortNumber(9042);
      ds.setKeyspaceName(MyKeyspace);
      ds.setUser("test");
      ds.setPassword("secret");
      // 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/ConnectCassandra", ds);
      } catch (Exception e) {
      System.out.println(e);
      return;
      }
   } // Main
   // class CassandraDataSourceRegisterJNDI