Access container services from EJBs

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 RAD 6.0 or during installation of the application EAR file onto the server.

In your code, do not look up the data source directly. Instead, you look up the resource reference from the java:comp/env namespace file.

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

DataSource appDS  = (DataSource) context.lookup("java:comp/env/jdbc/Section");
					

In the RAD 6.0, specify the name (jdbc/Section) as the resource reference. If you know the name of the DataSource, you specify it in the WebSphere Bindings section.

DataSource reference

ejb-jar.xml:


<resource-ref id="ResourceRef_1182173555396">
	<description>
	</description>
	<res-ref-name>jdbc/Section</res-ref-name>
	<res-type>javax.sql.DataSource</res-type>
	<res-auth>Container</res-auth>
	<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

					

BOOT.BY - Tech Industry News         Free SCBCD 1.3 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     Free IBM Certified Associate Developer Study Guide     Free SCJP 5.0 (Tiger) Study Guide     Free Mock Exam Engine     Free SCWCD 1.4 Study Guide     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide     Free SCBCD 5.0 Study Guide