Oracle8i Enterprise JavaBeans Developer's Guide and Reference
Release 3 (8.1.7)

Part Number A83725-01

Library

Solution Area

Contents

Index

Go to previous page Go to beginning of chapter Go to next page

Accessing EJB References and JDBC DataSources

You can access EJB references and JDBC DataSources through your bean's environment.

EJB References

The entity bean may create an environment reference for a target bean within the deployment descriptors. The URL of an EJB environment reference should have the following syntax:

"java:comp/env/ejb/"<ejb-ref-name>

The "java:comp/env/ejb" prefix is a subcontext that instructs JNDI to locate the EJB reference within the EJB references defined in the deployment descriptor. The <ejb-ref-name> is the logical environment name of the EJB reference defined in the deployment descriptor. The following shows how a bean looks up another bean's reference within its deployed environment:

Context ic = new InitialContext ( );

CustomerHome ch = (CustomerHome)ic.lookup ("java:comp/env/ejb/PurchaseOrder");

See "Environment References To Other Enterprise JavaBeans" for a full description of EJB environment references.

JDBC DataSources

The entity bean had the option of creating an environment reference for JDBC DataSources bound within JNDI. These were declared for the bean within the deployment descriptors. If defined, the serviceURL and objectName contains the URL of an EJB environment reference, which is of the following syntax:

"java:comp/env/jdbc/"<resource-ref-name>
     

The "java:comp/env/jdbc" prefix is a subcontext that instructs JNDI to locate the JDBC DataSource within the <resource-ref> elements defined in the deployment descriptor, which actually defines the logical environment name.

The following is the definition of the JDBC DataSource within the EJB deployment descriptor for the purchase order:

<resource-ref>
           <res-ref-name>jdbc/EmployeeAppDB</res-ref-name>
           <res-type>javax.sql.DataSource</res-type>
           <res-auth>Application</res-auth>
</resource-ref>


Note:

Only the Application option is supported for <res-auth> for this release.  


The following shows the JNDI context initialization for the purchase order example:

#import javax.sql.*

String dbURL = "java:comp/env/jdbc/EmployeeAppDB";

DataSource dbRes = (DataSource)ic.lookup (dbURL);
Connection conn = dbRes.getConnection;
     

See "Environment References To Resource Manager Connection Factory References" for a full description of JDBC DataSource variables.



Go to previous page
Go to beginning of chapter
Go to next page
Oracle
Copyright © 1996-2000, Oracle Corporation.

All Rights Reserved.

Library

Solution Area

Contents

Index