Reputation: 49
I need to connect to a mysql database via servlet. I understood that it's not enough to add the jar to the project (properties->java build path->add external), but I need also to add the jar to the classpath.
What means that? How to do it? I searched here for answer and didn't find, except the idea to copy-paste the jar to the src directory - that doesn't fix my problem.
My main problem is:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Upvotes: 2
Views: 738
Reputation: 12586
It depends on, which servlet container (== java web server) are you using. It is probably tomcat, but you need to share this information with us. My answer is for tomcat.
On tomcat, your application has somewhere a root directory (for example, /var/lib/tomcat/yourAppName
on linux).
Below this directory, there is a lib
subdirectory. This directory is already in your classpath, so it is enough to copy the needed jar into it.
There are much more complex solutions (for example, installing jars into the server classpath and into this application-specific lib
directory), but these are probably unneeded in your case.
Upvotes: 1