Varun
Varun

Reputation: 4452

HTTP Status 500 - javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.driver

Hi I'm new to jsp servlets

I am writing a simple login and registration application

I am trying to connect with MySQL through java code, but I am getting

HTTP Status 500 - javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.driver

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title></title>
</head>
<body>

<%
	String user=request.getParameter("uname");
	String pwd=request.getParameter("pass");
	String fname=request.getParameter("fname");
	String lname = request.getParameter("lname");
    String email = request.getParameter("email");
    Class.forName("com.mysql.jdbc.driver");
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test_database","root","Welcome123");
    Statement st=con.createStatement();
    //ResultSet rs;
    int i=st.executeUpdate("insert into members(first_name, last_name, email, uname, pass, regdate) values ('" + fname + "','" + lname + "','" + email + "','" + user + "','" + pwd + "', CURDATE())");
	if(i>0){
		   //session.setAttribute("userid", user);
        response.sendRedirect("welcome.jsp");
       // out.print("Registration Successfull!"+"<a href='index.jsp'>Go to Login</a>");
    } else {
        response.sendRedirect("index.jsp");
    }
	



%>



</body>
</html>

I have included the jar file as well, though I'm getting this error

mysql-connector-java-5.1.34-bin this is the jar file which I am using.

Upvotes: 1

Views: 2901

Answers (1)

gprathour
gprathour

Reputation: 15333

It should be com.mysql.jdbc.Driver.

You have written driver but the class name is Driver. So correct it and it should hopefully work.

Class.forName("com.mysql.jdbc.Driver");

Upvotes: 1

Related Questions