I get the following exception:
javax.naming.NamingException: Could not dereference object [Root exception is java.lang.NullPointerException]
when I try to connect to a DataSource with the following code (this is from a
Servlet):
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/JackalopeDB");
conn = ds.getConnection();
-------------------------------------------
JBoss deploys the MBean for the database properly.
Environment:
JBoss Version: jboss-3.2.0_tomcat-4.1.24
Database Server: MySQL v. 4.0.12
Database Driver: mysql-connector-java-3.1.0-alpha
Setup:
I don't use jboss.xml or jboss-web.xml
Here's the relevant portion of web.xml:
<resource-ref>
<description>Jackalope DB Connection</description>
<res-ref-name>jdbc/JackalopeDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
----------------------------------------------------
I copied the Driver's Jar file to %JBOSS_DIST%/server/default/lib to make sure it was on the JBoss CLASSPATH.
I copied %JBOSS_DIST%/docs/examples/jca/mysql-ds.xml to %JBOSS_DIST%/server/default/deploy and modified it to look like:
<datasources>
<local-tx-datasource>
<jndi-name>jdbc/JackalopeDB</jndi-name>
<connection-url>
jdbc:mysql://localhost:3306/jackalopedb?autoReconnect=true</connection-url>
<driver-class>org.gjt.mm.mysql.Driver</driver-class>
<user-name>jackalope</user-name>
<password>jackalope</password>
</local-tx-datasource>
</datasources>
I also had the same NullPointerException when I used MySQL Server v. 3.23.52 and MySQL Driver Version 2.0.14.
I don't think the problem is with the version of MySQL.
I must've configured things incorrectly.
What am I doing wrong?
Did I copy the driver to the right directory?
Does mysql-ds.xml look OK?
Is there another XML file that I need to modify. If so, which one and how?