- 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) {