How to do DataSource Binding, such that it is portable


EJB programming & troubleshooting: How to do DataSource Binding, such that it is portable

  1. Hi All, I'm bit confused with the JNDI bindings and the way they needs to be referred. For example i have a DataSource (I'm using MySQL). In ejb-jar.xml, I bound my datasource as jdbc/MySQL javax.sql.DataSource Container Shareable in jboss.xml, i have the following entry jdbc/MySQL java:comp/env/jdbc/MySQL and there is one mysql-ds.xml copied into deploy folder MySQL ............. Now my question is, how do I refer while looking up for the JNDI bound object, should I be referring as a) lookup("java:MySQL") - taken from mysql-ds.xml b) lookup("java:jdbc/MySQL") - taken from ejb-jar.xml c) lookup("java:comp/env/jdbc/MySQL") - taken from jboss.xml
  2. DS Binding[ Go to top ]

    In WAS6, you use option c. however, in was6 you put this entry in the web.xml through the gui editor and when you save it, was6 binds that info in ibm**bind.xml something file. only then it will work!
  3. When using indirect JNDI lookups, as you are, the URL you use from within you application is "java:comp/env/jdbc/MySQL". The "comp/env/" bit is the namespace reserved for doing indirect JNDI lookups. You could also remove the resource ref configuration from your ejb-jar.xml and jboss.xml and just use "java:/MySQL", that's a direct lookup. In your configuration below, there is a mistake in your jboss.xml, the JNDI name provided there is an indirect lookup, it should be a direct lookup, ie, java:/MySQL