求助。。。rs
cannot be resolved错误怎么办
package com.gdupt.servlet;
import
java.io.IOException;
import java.sql.*;
import
javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.gdupt.db.DataAccess;
import com.sun.org.apache.regexp.internal.RE;
public class LoginServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws
ServletException,
IOException {
//获得用户输入
String userno=req.getParameter("userno");
String userpsw=req.getParameter("userpsw");
//数据库连接对象
Connection conn=DataAccess.getConnection();
String sql="select * from tbluser where userno=? and userpsw?";
try{
//创建查询对象
PreparedStatement prest= conn.prepareStatement(sql);
prest.setString(1, userno);
prest.setString(2, userpsw);
//处理查询结果
if(rs.next()) {
PrintWriter out=resp.getWriter();
out.print("Welcome");
} else {
resp.sendRedirect("index.jsp");
}
rs.close();
prest.close();
}catch (
SQLException e) {
resp.sendRedirect("index.jsp");
}
}
}
------解决方案--------------------userpsw? 这个拼写错了啊
------解决方案--------------------rs都没看到定义。还有这里and userpsw?";
也有问题,
应该写成这样String sql="select * from tbluser where userno=? and userpsw=?";
然后在prest.setString(2, userpsw);下面写
ResultSet rs=prest.executeQuery();
------解决方案-------------------- 2 楼正解
------解决方案--------------------if(rs.next()) {
PrintWriter out=resp.getWriter();
out.print("Welcome");
改成
if(rs.next()) {
out.print(rs.getString(1));
out.print(rs.getString(2));
out.print("Welcome");
------解决方案--------------------
------解决方案--------------------重新贴 改之后的代码。。
------解决方案--------------------这是个P错误,这是最基本的变量声明赋值都没弄明白。
out是什么,上文里有吗?你要写jsp,out应该是response的Writer
你是不是只会复制粘贴?“人家粘了好使,我粘了不好使”,连复制粘贴你都粘不全。