Connection caches and security  Using Java Connection Manager classes

Chapter 26: Using Connection Management

Defining connection caches

A connection cache is an internal EAServer structure that maintains a pool of available connections to a third-tier server. All connections in the cache must share a common user name and password, all must connect to the same third-tier server, and all must use the same connectivity library.

Use EAServer Manager to define connection caches used by your application, as described in Chapter 4, “Database Access,” in the EAServer System Administration Guide.


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();

Application authentication

EAServer provides application authentication by allowing you to get a JDBC connection for a user name and password that you specify in the source code. This feature is supported for JDBC 2.0 ConnectionPoolDataSources only. This example gets a connection:

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

_conn = ds.getConnection(user_name, password);

// use the connection

_conn.close();

An application authenticated connection acts as a shared connection. Since only a single connection can be enlisted in a transaction, you cannot get two application authenticated connections, with different user name/password combinations in the same transaction. Attempts to do so can lead to unexpected results.





Copyright © 2005. Sybase Inc. All rights reserved. Using Java Connection Manager classes