【发布时间】:2016-05-01 09:20:03
【问题描述】:
这段代码给我的错误是结果集关闭后无法执行操作。我不明白出了什么问题。提前致谢。
<%@page import="java.sql.*"%>
<%
String username = request.getParameter("username");
String password = request.getParameter("password");
//JDBC CODE
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/**", "****", "******");
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("select * from add_user_table where name='"+username+"' and password='"+password+"'");
if(rs.next())
{
String name=rs.getString("name");
String pass = rs.getString("password");
if(username.equals(name) && password.equals(pass))
{
session.setAttribute("username",username);
response.sendRedirect("any.jsp");
}
else
{
response.sendRedirect"any2.jsp?msg=Invalid");
}
}
else
{
response.sendRedirect("any2.jsp?msg=Invalid");
}
}
catch(Exception e)
{
e.printStackTrace();
}
%>
【问题讨论】:
-
嗯,我不认为编写具有明显 SQL 注入风险的代码是一个好习惯。
-
需要堆栈跟踪。为什么要同时检查 SQL 和以下 Jaca 代码中的匹配项?
-
据我所知,显示的代码不会产生此错误。请发布堆栈跟踪。