I am receiving a nullpointer exception because of the following code returning null.
conn = ds.getConnection();
I've spent the whole evening trying to debug it, without any luck. And I'm aware of that there is a lot of posts about nullpointer exceptions with dataSource.getConnection(), but nothing has helped.
The website worked perfectly fine running on my Mac, but now I want to host it on my Raspberry Pi through Tomcat. I have installed Tomcat, and MySQL and set it all up. The website works, except for when it needs to use something from the database, when the nullpointer occurs.
- I have confirmed that ds is not null from:
ds = (DataSource) context.lookup("java:comp/env/jdbc/psite");
- I've tried different varians of getConnection, such as
DriverManager.getConnection(name,username,psw);
- On my Raspberry Pi in my Tomcat/lib I have my mysql-connector-...jar
My xml files looks like this:
Tomcat/conf/context.xml
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource
name="jdbc/psite"
auth="Container"
type="javax.sql.DataSource"
username="sonie"
password="******"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/psite
maxActive="8"
maxIdle="4" />
Tomcat/conf/server.xml
<Resource name="jdbc/psite"
global="jdbc/psite"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/psite"
username="sonie"
password="******"
maxActive="100"
maxIdle="20"
minIdle="5"
maxWait="10000"/>
MyProject/WEB-INF/web.xml
<resource-ref>
<res-ref-name>
jdbc/psite
</res-ref-name>
<res-type>
javax.sql.DataSource
</res-type>
<res-auth>
Container
</res-auth>
</resource-ref>
Any ideas what might be wrong? I'm pretty sure I've nailed it down to being some configuration problems on my Raspberry Pi, as it worked fine on my Mac previously.
EDIT:
Even though yes it is a Nullpointer, I haven't managed to debug it like a normal Nullpointer as it works fine on my Mac in eclipse, but not when it's deployed on the Raspberry Pi. So I can't get the printstack.
It's not duplicated because it's not possible to debug this like a normal NullPointer.