JDBC DataSource lookup

EAServer supports JNDI lookup of JDBC 2.0 DataSources to access ConnectionPoolDataSources and XADataSources, as illustrated in the following example. Only EJB components, Web applications, and application clients can use this feature, and you must define a resource reference to alias the connection cache to a JNDI name. For more information, see:

NoteJNDI access to connection caches requires JDBC 2.0 drivers Only connection caches that use a JDBC 2.0 driver can be aliased to JNDI resources. Specifically, the driver must implement the javax.sql.DataSource interface.

The JNDI lookup returns a DataSource interface, regardless of the cache configuration.

_cntxtProps = New Properties();
_cntxtProps.put(Context.INITIAL_CONTEXT_FACTORY,
              “com.sybase.ejb.InitialContextFactory”);
_cntxtProps.put(javax.naming.Context.PROVIDER_URL,
              “iiop://<host_name>:<port>”);

nameContext = new InitalContext(_cntxtProps);

_ds = (javax.sql.DataSource) nameContext.lookup(“java:comp/env/jdbc/myAlias2DB”);

_conn = ds.getConnection();

// use the connection

_conn.close();