|Oracle8i Enterprise JavaBeans Developer's Guide and Reference
Release 3 (8.1.7)
Part Number A83725-01
You can access EJB references and JDBC DataSources through your bean's environment.
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" 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.
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
objectName contains the URL of an EJB environment reference, which is of the following syntax:
"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>
The following shows the JNDI context initialization for the purchase order example:
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.