gpt4 book ai didi

java - 如何清除JSP程序中的数据库连接错误?

转载 作者:行者123 更新时间:2023-11-29 10:52:30 24 4
gpt4 key购买 nike

我试图将我的 JSP 登录文件链接到 MySQL 数据库,但收到如下错误。我还将 MySQL-connector jar 文件导入到项目中。我不知道为什么会收到此错误。请帮助我纠正我的错误。

我的代码:

<%@ page import ="java.sql.*" %>
<%
String userid = request.getParameter("uname");
String pwd = request.getParameter("pass");
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/college",
"root", "root");
Statement st = con.createStatement();
ResultSet rs;
rs = st.executeQuery("select * from studentdata where uname='" + userid + "' and pass='" + pwd + "'");
if (rs.next()) {
session.setAttribute("userid", userid);
//out.println("welcome " + userid);
//out.println("<a href='logout.jsp'>Log out</a>");
response.sendRedirect("success.jsp");
} else {
out.println("Invalid password <a href='index.jsp'>try again</a>");
}
%>

错误消息:

type Exception report

message An exception occurred processing JSP page /login.jsp at line 5

description The server encountered an internal error that prevented it from fulfilling this request.

exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /login.jsp at line 5

2: <%
3: String userid = request.getParameter("uname");
4: String pwd = request.getParameter("pass");
5: Class.forName("com.mysql.jdbc.Driver");
6: Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/college",
7: "root", "root");
8: Statement st = con.createStatement();


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)



root cause
javax.servlet.ServletException: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:916)

最佳答案

您收到此错误:

java.lang.ClassNotFoundException:com.mysql.jdbc.Driver

建议:

1.- 驱动程序 mysql****.jar 是否位于 WEB-INF/lib 文件夹中?

2.- 您是否在类路径中注册了它?

希望对你有帮助

关于java - 如何清除JSP程序中的数据库连接错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43477391/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com