Looking up data sources with resource references for relational access
WAS requires a resource reference to access a data source or connection factory:
If a data source is looked up directly, the connection gets all default properties for the missing resource reference. For example, the sharing-scope is a shareable connection resulting in the possibility that the physical connection is the same each time the connection is requested from the data source. This situation can cause a multitude of problems if you expect unshareable connections.
It relieves the programmer from having to know the name of the actual data source at the target appserver.
One can set the default isolation level for the data source through resource references. With no resource reference you get the default for the JDBC driver you use.
Use a resource reference (resource-ref) for looking up a data source through the standard JNDI naming interface. The JNDI name defined in the resource-ref is a logical name of the data source. Have your application use this JNDI name to look up a data source instead of using the JNDI name that is defined on the data source.
Later, you can substitute the real name, either by using the Application Assembly Tool or during installation of the application EAR file onto the server.
For example, assume that you use a DataSource jdbc/foobar as illustrated in the code below.
javax.sql.DataSource specificDataSource = (javax.sql.DataSource) javax.rmi.PortableRemoteObject.narrow ( (new InitialContext()).lookup("java:comp/env/jdbc/foobar"), javax.sql.DataSource.class );
In the AAT, or when deploying the EAR file, specify the name (jdbc/foobar) as the resource reference and specify the data source name in the resource references Bindings page.
Isolation level and resource reference
Data sources
Accessing data from application clients
Configure data access for application clients
Creating or changing a resource reference
Assembling data access applications
Accessing data using J2EE Connector Architecture connectors
Creating and configuring a JDBC provider and data source