Reputation: 211
I have my LoadDriver class which is working as intended (no error)
package p_test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class LoadDriver {
public static void Load() {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Then I have my jsp file
<%@ page import="p_test.LoadDriver"%>
<% LoadDriver.Load(); %>
When i run it he cant find the driver
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1320)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1173)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at p_test.LoadDriver.Load(LoadDriver.java:16)
I am using tomcat 8.0. I just started with jsp so i dont know where the program searches the driver!
And if someone can recommend a good JSP Book or an online tutorial that would be great.
Upvotes: 2
Views: 3810
Reputation: 915
You need to add mysql driver to your project lib. You will find driver jar file here MYSQL DRIVER
You can refer this link JSP MYSQL EXAMPLE for better understanding.
Welcome to JSP World :)
Upvotes: 0
Reputation: 72844
You need to have the MySQL JDBC connector in your classpath. You can place the Jar in your WEB-INF/lib
folder of your project.
Or you can place it under CATALINA_HOME/lib
to be available for all your applications where CATALINA_HOME
is an environment variable pointing to the root of your Tomcat installation.
Upvotes: 3
Reputation: 3570
You don't have MySql driver in your classpath. You have to place mysql connector jar inside WEB-INF/lib folder of your app
Upvotes: 0