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

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

嗨,我是 jsp servlets 的新手

我正在写一个简单的登录和注册应用程序

我正在尝试通过 java 代码连接 MySQL,但我收到

HTTP 状态 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>

我也包含了 jar 文件,但是我收到了这个错误

mysql-connector-java-5.1.34-bin 这是我正在使用的jar文件。

应该是com.mysql.jdbc.Driver.

您写的是 driver,但 class 的名字是 Driver。所以更正它,它应该可以正常工作。

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