Looking up data sources with resource references

 

WAS requires that you use a resource reference to access data sources and connection factories. Some of the reasons include:

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 Assembly Toolkit (ATK) or during installation of the application EAR file onto the server.

For example, assume that you use a DataSource jdbc/Section as illustrated in the code below.

javax.sql.DataSource specificDataSource = 
   (javax.sql.DataSource) javax.rmi.PortableRemoteObject.narrow( 
   (new InitialContext()).lookup("java:comp/env/jdbc/Section"),
   javax.sql.DataSource.class);

In the ATK, specify the name (jdbc/Section) as the resource reference. If you know the name of the DataSource, you specify it in the resource references Bindings page.