为什么我在jsp中执行executequery后,数据库数据进去了,但报错SQLException: No ResultSet was produced
jie_c 2002-05-09 10:57:22 执行第一个没问题,第二个有问题.]
而且session的赋值放在if外就不对
<%@ page contentType="text/html; charset=GBK" %>
<%@ page language="java" import="java.sql.*,java.io.*,java.lang.*"%>
<%@ page session="True"%>
<html>
<head>
<title>
login12345
</title>
</head>
<body>
<!--//头文件header.inc-->
<%--@ include file="header.inc"--%>
<%String nm,pwd;
nm = request.getParameter("nm");
pwd = request.getParameter("pwd");
%>
<%
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
String url="jdbc:odbc:new_db";
//pubs为你的数据库的
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from t_user where user_id='"+nm+"' and passwd='"+pwd+"'";
ResultSet rs=stmt.executeQuery(sql);
if (rs.next())
{out.println("yes");
String username;
String uid;
String did;
did=rs.getString("dept_id");
username=rs.getString("user_name");
uid=rs.getString("user_id");
session.putValue("userid",uid);
session.putValue("deptid",did);
String sql1="insert into t_log(user_name,user_id,log_datetime) values('"+username+"','"+uid+"',getdate())";
ResultSet rs1=stmt.executeQuery(sql1);
response.sendRedirect("Jsp1.jsp");
}
else
{out.println("no");
response.sendRedirect("indexerr.htm");
}
}
catch(Exception e)
{
out.println(e.toString()+"12343");
}
%>
</body>
<!--//尾文件footer.inc-->
<%--@ include file="footer.inc"--%>
</html>