回 帖 发 新 帖 刷新版面

主题:请问这个错误怎么解决!

java.lang.NullPointerException
    bookshop.run.login.excute(login.java:65)
    org.apache.jsp.bookshop.login_jsp._jspService(login_jsp.java:71)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)



package bookshop.run;
/**
 * <p>管理用户登录的类 </p>
 */
import bookshop.util.*;
public class login extends DataBase {
        private String username;    //登录用户名
        private String passwd;        //登录密码
        private boolean isadmin;    //是否管理员登录
        private long userid=0;        //用户ID号
        public login() throws Exception{
                super();
                username = "";
                passwd = "";
                isadmin = false;
        }
        public String getUsername() {
                return username;
        }
        public void setUsername(String newusername) {
                username = newusername;
        }
        public String getPasswd() {
                return passwd;
        }
        public void setPasswd(String newpasswd) {
                passwd = newpasswd;
        }
        public boolean getIsadmin() {
                return isadmin;
        }
        public void setIsadmin(boolean newIsadmin) {
                isadmin = newIsadmin;
        }
        public long getUserid() {
                return userid;
        }
        public void setUserid (long uid) {
                userid = uid;
        }
        /**
         * 获得查询用户信息的sql语句
         * @return
         */
        public String getSql() {
                if (isadmin) {
                        sqlStr = "select * from BookAdmin where adminuser = '" +
                            dataFormat.toSql(username) + "' and adminpass = '" +
                            dataFormat.toSql(passwd) + "'";
                }else {
                        sqlStr = "select * from shop_user where username = '" +
                            username + "' and password = '" + passwd + "'";
                }
                return sqlStr;
        }
        /**
         * 执行查询
         * @return
         * @throws java.lang.Exception
         */
        public boolean excute() throws Exception {
                boolean flag = false;
                DataBase db = new DataBase();
                db.connect();
                stmt = db.conn.createStatement ();
                rs = stmt.executeQuery(getSql());
                if (rs.next()){
                        if (!isadmin)
                        {
                                userid = rs.getLong("id");
                        }
                        flag = true;
                }
                rs.close();
                return flag;
        }
};


总是过不去 不知如何去修改 望大家帮我把程序调试过去

回复列表 (共1个回复)

沙发

public boolean excute() throws Exception {
                boolean flag = false;
                DataBase db = new DataBase();
                db.connect();
                stmt = db.conn.createStatement ();
                rs = stmt.executeQuery(getSql());
                if (rs.next())//这一句有可能没有查到结果(空异常)哦,那你怎么next()呢,所以要先判断,如if(rs!=null){......}
                {
                        if (!isadmin)
                        {
                                userid = rs.getLong("id");
                        }
                        flag = true;
                }
                rs.close();
                return flag;
        }

我来回复

您尚未登录,请登录后再回复。点此登录或注册