Reputation: 3401
I'm rebuilding my development environment and I can't get JDBC working. I'm running Tomcat 7 under Eclipse Java EE Mars.2 and am using mysql-connector-java. Also Linux Mint 17.2. I upgraded to latest on a bunch of things but I don't think that's it.
When I start the Tomcat server under Eclipse, I keep getting the following. I'm not running it separately on this machine. Just under Eclipse.
SEVERE:
Servlet.service() for servlet [jsp] in context with path [] threw exception [javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.lang.NullPointerException"] with root cause
javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.lang.NullPointerException"
I assume this means it cannot find the driver? All the file structures are the same as my old PC. And the IDE is not complaining about anything missing. It's just when I try to start the server.
I added the mysql-connector-java-5.1.39-bin.jar
to the Tomcat/lib folder. Specifically: /opt/apache-tomcat-7.0.69/lib
. And I made sure the Server is referencing that folder. I also made sure it is not in the webapp's lib folder. This is how I always did it before.
I assume it's a driver thing. But maybe not? Can someone please suggest a good way to debug this? Because, I'm stumped...
META-INF/context.xml
is as it's been from the previous environment. Password is correct and can connect from the IDE no problem.
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="jdbc/mydbdb"
auth="Container"
type="javax.sql.DataSource"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
driverClassName="com.mysql.jdbc.Driver"
testWhileIdle="true" testOnBorrow="true" testOnReturn="false"
validationQuery="SELECT /* ping */" validationInterval="30000"
timeBetweenEvictionRunsMillis="30000"
maxActive="100" minIdle="10" maxWait="10000" initialSize="10"
removeAbandonedTimeout="600" removeAbandoned="true" logAbandoned="true"
minEvictableIdleTimeMillis="30000"
jmxEnabled="true"
username="user" password="password"
useUnicode="true" useEncoding="true" characterEncoding="UTF-8"
url="jdbc:mysql://localhost:3306/mydb?useOldAliasMetadataBehavior=true&zeroDateTimeBehavior=convertToNull"
/>
<Resource name="mail/MailSession"
auth="Container"
type="javax.mail.Session"
mail.smtp.auth="false"
mail.smtp.host="localhost"
/>
</Context>
Upvotes: 1
Views: 3770
Reputation: 3401
It is with great embarrassment that I admit I forgot to copy the web.xml file from the old environment... Doh! Sitting so close... Sometimes you can't see the forest for the trees.
Upvotes: 1
Reputation: 1685
If you double-click your Tomcat instance under Eclipse it will take you to the setting for the server, and from there you can select the "Open Launch Configuration" option where you can add your driver jar to the bootstrap classpath.
That said, I don't think the problem is a missing driver as that generally results in a "Class not found" exception. Check your logs carefully and maker sure you're not getting any errors. I'm making the assumption that you're letting Tomcat open your database connections to create a datasource. It seems like you don't have your data source configured in your Tioomcat server.xml and context.xml and therefore your servlet is throwing a null pointer exception when trying to use it.
Upvotes: 0