首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

又是Null?该如何解决

2013-09-11 
又是Null?Java codepackage com.fuyou.servletimport java.io.IOExceptionimport java.sql.ResultSetim

又是Null?

Java code
package com.fuyou.servlet;import java.io.IOException;import java.sql.ResultSet;import java.sql.SQLException;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import com.fuyou.util.DBConnection;import com.fuyou.util.mvconnection;public class loginservlet extends HttpServlet {    private DBConnection dbc = new DBConnection();    private static final long serialVersionUID = -3265621922663327137L;    public loginservlet() {    }    public void destroy() {        super.destroy();    }    public void doGet(HttpServletRequest request, HttpServletResponse response)            throws ServletException, IOException {        doPost(request, response);    }    public void doPost(HttpServletRequest request, HttpServletResponse response)            throws ServletException, IOException {        String username = request.getParameter("username");        String password = request.getParameter("password");        String conformPswd = "";        String sql = "select * from user where username='" + username + "'";        ResultSet rs = null;        mvconnection mvc = new mvconnection();        if (mvc != null) {            rs = mvc.getResultSet(sql);        } else {            return;        }        if (rs != null) {            try {                if (rs.getString("password") != null) {                    conformPswd = rs.getString("PASSWORD");                }                return;            } catch (SQLException e) {                e.printStackTrace();            } finally {                this.dbc.closeResultSet(rs);            }        }        if (password.equals(conformPswd)) {        }    }    public void init() throws ServletException {    }}
异常信息:
type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

java.lang.NullPointerException
com.mysql.jdbc.ResultSet.buildIndexMapping(ResultSet.java:596)
com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:946)
com.mysql.jdbc.ResultSet.getString(ResultSet.java:5613)
com.fuyou.servlet.loginservlet.doPost(loginservlet.java:50)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)




[解决办法]
哪是第50行哦,数了半天数到try去了,看来代码给的不准确哟。
[解决办法]
不可能哟,你上头已经判断了rs != null咯,下面咋也没有其他可能是null咯,再查查撒。
[解决办法]
mvconnection mvc = new mvconnection();
mvc.getResultSet(sql);
把这mvconnection类及相关代码贴上来
[解决办法]
哦,好像有点儿明白了,原来是因为column不存在,所以不是你代码里的null,而是mysql驱动里出现了null。原来如此。

com.mysql.jdbc.ResultSet.buildIndexMapping(ResultSet.java:596)
唉。老花眼啦。("password") ,这一行啊,怕是在数据库里不存在吧?

如果确实不是数据库,就可能是驱动包本身有问题了,咱们也懒得看他的代码,要不换个别的版本?
[解决办法]
com.mysql.jdbc.ResultSet.buildIndexMapping
rs在创建索引对象影射的时候null了 是不是缺这种之类的
Java code
rs.hasNext()
[解决办法]
嘿嘿,没法了,换驱动吧。
[解决办法]
你的这段程序好像不怎么对:
if (rs != null) {


应当转换成:
if (rs != null && rs.hasNext() ) {
rs.next();
.....
 
[解决办法]
/* 验证方法 */
public boolean valieLogin(String userName,String passWord) {
boolean sucess = false;

Connection conn = null;
PreparedStatement pst = null;
ResultSet rs = null;
conn = DBConnection.getSQL();
try {
pst = conn
.prepareStatement("select * from user_login where userId=? and userPass=?");
pst.setString(1,userName);
pst.setString(2, passWord);
rs = pst.executeQuery();
if (rs.next()) {

sucess = true;
}
} catch (SQLException e) {

e.printStackTrace();

} finally {

try {
if (rs != null) {
rs.close();
rs = null;
}
if (pst != null) {
pst.close();
pst.close();
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}

return sucess;

}



[解决办法]
那应该是next了

Java code
ResultSet rs=s.executeQuery("select * from friends");
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html

热点排行