How do you get a JDBC database registered with a JNDI name so that it can be accessed from an EJB?
The res-ref-name is the most interesting part. This is the JNDI name relative to the java:comp/env namespace. Hence, to get this connection you'd do (in your bean):<resource-ref> <res-ref-name>jdbc/LocalDB2<res-ref-name> <res-type>javax.sql.DataSource<res-type> <res-auth>Container<res-auth> <resource-ref>
which gives you a DataSource that you can call getConnection on.Context context = new InitialContext(); DataSource source = context.lookup("java:comp/env/jdbc/LocalDB2");
The other half of this is container specific and done at deployment time by a 'Deployer' or 'Assembler' (to use the rolenames specified by the EJB spec.) This can work very differently from one container to the next, but here are a couple of (abbreviated) examples.
With Weblogic 5.1, you must define a connection pool in weblogic.properties, then edit the weblogic specific deployment descriptor (using the EJB Deployment tool) to associate the resource-ref specified in ejb-jar.xml with that connection pool.
Other servers will have other ways of associating the resource-ref with a pre-defined connection pool.