<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.io.*" errorPage="errorpage.jsp" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>验证</title>
</head>
<body>
<%
Connection con=null;try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String spath="\\db1.mdb";
String dbpath=application.getRealPath(spath);
String url="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="+dbpath;
con=DriverManager.getConnection(url);
Statement stmt=con.createStatement();
String textfile2=new String(request.getParameter("textfile1").getBytes ("iso8859_1"),"gbk");
String password3=new String(request.getParameter("password1").getBytes ("iso8859_1"),"gbk");
String rand = (String)session.getAttribute("rand");
String input = request.getParameter("rand");
String sql1="select * from test where textfile2='"+textfile2+"' and password3='"+password3+"'";
ResultSet rs=stmt.executeQuery(sql1);
String sql2="select textfile2 from test where textfile2='"+textfile2+"'" ;
ResultSet rsc=stmt.executeQuery(sql2); if(rs.next()&&rand.equalsIgnoreCase(input))
{
%>
<meta http-equiv="refresh" content="0;url=deng.jsp">
<%
}
else
{ if(rsc.next())
{
out.println("<script>alert('密码有误!!');</script>");%>
<meta http-equiv="refresh" content="0;url=index.jsp">
<%
}
else if(rand.equalsIgnoreCase(input))
{
out.println("<script>alert('用户名不存在!!');</script>");%>
<meta http-equiv="refresh" content="0;url=index.jsp">
<%
}
else
{
out.println("<script>alert('验证码有误!!');</script>");%>
<meta http-equiv="refresh" content="0;url=index.jsp">
<% }}
rsc.close();
rs.close();stmt.close();
con.close();
}catch(Exception e){
out.println(e.getMessage());
}
%>
</body>
</html>
结果是显示Resultset is closed
请问这是怎么回事啊?应该怎么解决啊??
谢谢
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>验证</title>
</head>
<body>
<%
Connection con=null;try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String spath="\\db1.mdb";
String dbpath=application.getRealPath(spath);
String url="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="+dbpath;
con=DriverManager.getConnection(url);
Statement stmt=con.createStatement();
String textfile2=new String(request.getParameter("textfile1").getBytes ("iso8859_1"),"gbk");
String password3=new String(request.getParameter("password1").getBytes ("iso8859_1"),"gbk");
String rand = (String)session.getAttribute("rand");
String input = request.getParameter("rand");
String sql1="select * from test where textfile2='"+textfile2+"' and password3='"+password3+"'";
ResultSet rs=stmt.executeQuery(sql1);
String sql2="select textfile2 from test where textfile2='"+textfile2+"'" ;
ResultSet rsc=stmt.executeQuery(sql2); if(rs.next()&&rand.equalsIgnoreCase(input))
{
%>
<meta http-equiv="refresh" content="0;url=deng.jsp">
<%
}
else
{ if(rsc.next())
{
out.println("<script>alert('密码有误!!');</script>");%>
<meta http-equiv="refresh" content="0;url=index.jsp">
<%
}
else if(rand.equalsIgnoreCase(input))
{
out.println("<script>alert('用户名不存在!!');</script>");%>
<meta http-equiv="refresh" content="0;url=index.jsp">
<%
}
else
{
out.println("<script>alert('验证码有误!!');</script>");%>
<meta http-equiv="refresh" content="0;url=index.jsp">
<% }}
rsc.close();
rs.close();stmt.close();
con.close();
}catch(Exception e){
out.println(e.getMessage());
}
%>
</body>
</html>
结果是显示Resultset is closed
请问这是怎么回事啊?应该怎么解决啊??
谢谢
String sql2="select textfile2 from test where textfile2='"+textfile2+"'" ;
ResultSet rsc=stmt.executeQuery(sql2);
你定义2个ResultSet 使用同一个连接,当执行第二个时候第一个ResultSet 应该已经关闭了。
String sql2="select textfile2 from test where textfile2='"+textfile2+"'" ;
ResultSet rsc=stmt.executeQuery(sql2);同一个连接,创建2个结果集?
建议LZ写一个公共的DBConn()类, 里面封装一些方法. 你的问题是只创建了一个Statement, 怎么可以啊.
Statement stmt1=con.createStatement(); //对应rs
Statement stmt2=con.createStatement(); //对应rsc
String rand = (String)session.getAttribute("rand"); 这个session在哪?