Section EJB.14.4 specifies how an enterprise bean should obtain connections to resources such as JDBC API connections. The connection acquisition protocol uses resource manager connection factory references that are part of the enterprise bean's environment. The following is an example of how an enterprise bean obtains a JDBC connection: public class EmployeeServiceBean implements SessionBean { EJBContext ejbContext; public void changePhoneNumber(...) { ... // obtain the initial JNDI context Context initCtx = new InitialContext(); // perform JNDI lookup to obtain resource manager connection // factory javax.sql.DataSource ds = (javax.sql.DataSource) initCtx.lookup("java:comp/env/jdbc/EmployeeAppDB"); // Invoke factory to obtain a connection. The security // principal is not given, and therefore // it will be configured by the Deployer. java.sql.Connection con = ds.getConnection(); ... } } |