Looking up data sources with resource references for relational access

Using a resource reference to access your data source or connection factory is required when running in WebSphere Application Server. Some of the reasons follow:

Use a resource reference (resource-ref) for looking up a data source through the standard Java Naming and Directory Interface (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) (new InitialContext()).lookup("java:comp/env/jdbc/Section"); 
   

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.


Related concepts
Binding to a data source[5.0 only][Version 5.0.1][Version 5.0.2]
Data sources
Related tasks
Migrating a version 4.0 data access application to version 5.1
Creating and configuring a JDBC provider and data source



Searchable topic ID:   datsorres
Last updated: Jun 21, 2007 4:12:58 PM CDT    WebSphere Application Server Express, Version 5.0.2
http://publib.boulder.ibm.com/infocenter/wasinfo/index.jsp?topic=/com.ibm.websphere.exp.doc/info/exp/ae/cdat_datsorres.html

Library | Support | Terms of Use | Feedback