I have a short jsp page that tries to establish the connection to the mySQL database named 'test'. I tried to deploy it properly in Tomcat but with no success. All other jsp pages work well. This page gives an error when executed. I'm still a student & I'm trying experimenting on this. I already got the mysql-connector-java-5.1.16-bin.jar & tried putting it to the places in the answers that I found when i googled this question. The jsp page includes;
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
Connection con = null;
try
{
String connectionURL = "jdbc:mysql://localhost:3306/test";
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection(connectionURL);
}
catch(SQLException ex)
{
throw new ServletException("Servlet could not display records.",ex);
}
catch(ClassNotFoundException ex)
{
throw new ServletException("JDBC Driver not found",ex);
}
The errors are;
org.apache.jasper.JasperException: An exception occurred processing JSP page /access_exp_two.jsp at line 72
69: {
70: String connectionURL = "jdbc:mysql://localhost:3306/test";
71:
72: Class.forName("com.mysql.jdbc.Driver").newInstance();
73: con = DriverManager.getConnection(connectionURL);
74:
75: }
.....
root cause
javax.servlet.ServletException: JDBC Driver not found
.....
root cause
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
.....
I think this sort of error occurs because I haven't deployed everything in Tomcat correctly. It would be a huge help if someone could clearly state how to state a resource in the web.xml file, modify the context.xml file (further more I didn't quite understand which context.xml file everyone refers to, because it's different in each answer). This might be a unsuitable question, but please at least point me in the right way. Thanks a lot, in advance.