| Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g (10.1.3.5.0) Part Number E13981-01 |
|
|
View PDF |
Using EJB 2.1, you can look up a resource manager connection factory using the InitialContext (see "Using Initial Context").
For more information on configuring resources, see "Resource Manager Connection Factory Environment References".
Example 19-30 shows how to look up a JDBC data source resource manager connection factory within the bean's code using the InitialContext with the logical name defined in the EJB deployment descriptor (see "Configuring an Environment Reference to a JDBC Data Source Resource Manager Connection Factory") prefixed with java:comp/env/jdbc.
Example 19-30 Looking Up a JDBC Data Source Resource Manager Connection Factory
javax.sql.DataSource db;
java.sql.Connection conn;
...
InitialContext ic = new InitialContext();
db = (javax.sql.DataSource) initCtx.lookup("java:comp/env/jdbc/OrderDB");
conn = db.getConnection();
For more information, see "Configuring the Initial Context Factory".