gpt4 book ai didi

java - 登录页面输入正确的用户名和密码

转载 作者:行者123 更新时间:2023-12-01 17:37:09 25 4
gpt4 key购买 nike

即使输入了正确的用户名和密码组合,登录页面也会显示一条错误消息,指示登录失败。造成这个问题的原因是什么?

try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:mydsn","sa","password@123");
String sql = "select customer_id, fname, lname, email_id, phone_number from customer_details where user_name=? and password=?";
PreparedStatement stmt;
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
session.setAttribute("customerId", rs.getString(1));
session.setAttribute("userName", userName);
session.setAttribute("fName", rs.getString(2));
session.setAttribute("lName", rs.getString(3));
session.setAttribute("emailId", rs.getString(4));
session.setAttribute("phoneNumber", rs.getString(5));
conn.close();
%>
<jsp:forward page="welcome.jsp" />
<%} else {%>
Sorry! You have entered an invalid username or password. Please try again.
<%}
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}

最佳答案

这是因为

PreparedStatement stmt;
ResultSet rs = stmt.executeQuery();

stmtnull

对您的代码的一些建议:

关于java - 登录页面输入正确的用户名和密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5151588/

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