For mysql-ds.xml :
<datasources> <local-tx-datasource> <jndi-name>MySQLDS</jndi-name> <connection-url>jdbc:mysql://192.168.1.50:3306/webapp</connection-url> <driver-class>org.gjt.mm.mysql.Driver</driver-class> <user-name>x</user-name> <password>y</password> </local-tx-datasource> </datasources>
for web.xml :
<resource-ref> <description>The default DS</description> <res-ref-name>MySQLDS</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
for jboss-web.xml :
<resource-ref> <res-ref-name>MySQLDS</res-ref-name> <jndi-name>java:/MySQLDS</jndi-name> </resource-ref>
Context initialContext = new InitialContext(); Context env = (Context) initialContext.lookup("java:comp/env"); DataSource ds = (DataSource) env.lookup("MySQLDS");
I Hope it helps
It does, although i'd like to know why -- what was it that i was doing wrong in my naming?
In a slightly related note, where should i be putting the driver jar file for this? I'm getting a ClassNotFoundException when i try to initialize the connection, so obviously i'm going about it wrong. My mysql driver jar file is currently in $JBOSS_HOME/lib
I have my jdbc jar file in $JBOSS_HOME/servers/default/lib, it needs to be in the lib under whatever server you are using.
I figured that one out with embarassingly little googling. Silly me.
At any rate, i still don't know what i was doing wrong in web.xml and jboss-web.xml. I'd love to hear, though.
1) The <res-ref-name> in web.xml and jboss-web.xml must be the same.
2) According to your mysql-ds.xml, the jndi name for your datasource is java:/MySQLDS at deployment time because the comp/env environment is not yet set.
3) Then, in your servlet, the lookup mus be done in java:comp/env/<res-ref-name>
Is this what you want ot know ?