HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception java.lang.NullPointerException
com.wy.tool.JDBConnection.executeQuery(JDBConnection.java:52)
com.wy.dao.ConsumerDao.getConsumerForm(ConsumerDao.java:98)
com.wy.webiter.ConsumerServlet.checkConsumer(ConsumerServlet.java:169)
com.wy.webiter.ConsumerServlet.doGet(ConsumerServlet.java:16)
com.wy.webiter.ConsumerServlet.doPost(ConsumerServlet.java:186)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.20 logs.
--------------------------------------------------------------------------------Apache Tomcat/5.5.20
请问如何解决?

解决方案 »

  1.   

    JDBConnection.java:52行空指针异常
      

  2.   

    随书光盘例子来的,未改动过,我上百度查了一下,也知道大概是空指针问题,JDBConnection.java:52行空指针异常,之类,不过我看了代码,找不出什么毛病,而且是明日科技的随书光盘例子来的,我是在登陆时出现这个错误的:
    以下为代码,各位帮忙看下,//JDBConnection.java 代码:package com.wy.tool;import java.sql.*;public class JDBConnection {
        private final String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_BlodMay";
        private final String userName = "sa";
        private final String password = "";
        private Connection con = null;
    //通过构造方法加载数据库驱动
        static {
            try {
                Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); 
            } catch (Exception ex) {
                System.out.println("数据库加载失败");
            }
        }
    //创建数据库连接
        public boolean creatConnection() {
            try {
                con = DriverManager.getConnection(url, userName, password);
                con.setAutoCommit(true);        } catch (SQLException e) {
                System.out.println(e.getMessage());
                System.out.println("creatConnectionError!");
            }
            return true;
        }
    //对数据库的增加、修改和删除的操作
        public boolean executeUpdate(String sql) {
             if (con == null) {
                creatConnection();
            }
            try {
                Statement stmt = con.createStatement();
                int iCount = stmt.executeUpdate(sql);
                System.out.println("操作成功,所影响的记录数为" + String.valueOf(iCount));
        return true;
            } catch (SQLException e) {
                System.out.println(e.getMessage());
        return false;
            }   
        }
    //对数据库的查询操作
        public ResultSet executeQuery(String sql) {
            ResultSet rs;
            try {
                if (con == null) {
                    creatConnection();
                }
                Statement stmt = con.createStatement();
                try {
                    rs = stmt.executeQuery(sql);
                } catch (SQLException e) {
                    System.out.println(e.getMessage());
                    return null;
                }
            } catch (SQLException e) {
                System.out.println(e.getMessage());
                System.out.println("executeQueryError!");
                return null;
            }
            return rs;
        }
    }//ConsumerDao.java 代码:package com.wy.dao;import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.*;import com.wy.form.ConsumerForm;
    import com.wy.tool.JDBConnection;public class ConsumerDao {
    private JDBConnection connection = null; private ConsumerForm consumerForm = null; public ConsumerDao() {
    connection = new JDBConnection();
    } // 以数据库编号为条件,修改用户信息
    public boolean front_updateConsumerForm(ConsumerForm form) {
    boolean flag = false;
    String sql = "update tb_consumer set account='" + form.getAccount()
    + "',password='" + form.getPassword() + "',name='"
    + form.getName() + "',sex='" + form.getSex() + "',QQNumber='"
    + form.getQQNumber() + "',mainPage='" + form.getMainPage()
    + "',interest='" + form.getInterest() + "',eMail='"
    + form.getEMail() + "' where id='" + form.getId() + "'";
    if (connection.executeUpdate(sql)) {
    flag = true;
    }
    return flag;
    } // 更新用户操作 public boolean updateConsumerForm(ConsumerForm form) {
    boolean flag = false;
    String sql = "update tb_consumer set account='" + form.getAccount()
    + "',password='" + form.getPassword() + "',name='"
    + form.getName() + "',sex='" + form.getSex() + "',QQNumber='"
    + form.getQQNumber() + "',mainPage='" + form.getMainPage()
    + "',interest='" + form.getInterest() + "',eMail='"
    + form.getEMail() + "' where manageLevel='"
    + form.getManageLevel() + "'";
    if (connection.executeUpdate(sql)) {
    flag = true;
    }
    return flag;
    } // 删除用户信息
    public boolean deleteConsumerForm(String account) {
    boolean flag = false;
    String sql = "delete from tb_consumer where account='" + account + "'";
    if (connection.executeUpdate(sql)) {
    flag = true;
    }
    return flag;
    } // 添加用户信息
    public boolean addConsumerForm(ConsumerForm form) {
    boolean flag = false;
    String sql = "insert into tb_consumer values ('" + form.getAccount()
    + "','" + form.getPassword() + "','" + form.getName() + "','"
    + form.getSex() + "','" + form.getQQNumber() + "','"
    + form.getMainPage() + "','" + form.getInterest() + "','"
    + form.getEMail() + "','" + form.getManageLevel() + "')"; if (connection.executeUpdate(sql)) {
    flag = true;
    }
    return flag;
    }

    public String getConsumerForm(Integer id) {
    String sql = "select * from tb_consumer where id='" + id
    + "'";
    String name="";
    try {
    ResultSet rs = connection.executeQuery(sql);
    while (rs.next()) {
    name=rs.getString("name");
    }
    } catch (SQLException e) {
    e.printStackTrace();
    }
    return name;
    }



    // 以用户名为查询条件,查询一组数据
    public ConsumerForm getConsumerForm(String account) {
    String sql = "select * from tb_consumer where account='" + account
    + "'";
    try {
    ResultSet rs = connection.executeQuery(sql);
    while (rs.next()) {
    consumerForm = new ConsumerForm();
    consumerForm.setId(Integer.valueOf(rs.getString(1)));
    consumerForm.setAccount(rs.getString(2));
    consumerForm.setPassword(rs.getString(3));
    consumerForm.setName(rs.getString(4));
    consumerForm.setSex(rs.getString(5));
    consumerForm.setQQNumber(rs.getString(6));
    consumerForm.setMainPage(rs.getString(7));
    consumerForm.setInterest(rs.getString(8));
    consumerForm.setEMail(rs.getString(9));
    consumerForm.setManageLevel(rs.getString(10));
    }
    } catch (SQLException e) {
    e.printStackTrace();
    }
    return consumerForm;
    } // 根据用户账号查询所有的数据
    public List getConsumerList(String manageLevel) {
    List list = new ArrayList();
    String sql = "select * from tb_consumer where manageLevel='"
    + manageLevel + "'";
    try {
    ResultSet rs = connection.executeQuery(sql);
    while (rs.next()) {
    consumerForm = new ConsumerForm();
    consumerForm.setId(Integer.valueOf(rs.getString(1)));
    consumerForm.setAccount(rs.getString(2));
    consumerForm.setPassword(rs.getString(3));
    consumerForm.setName(rs.getString(4));
    consumerForm.setSex(rs.getString(5));
    consumerForm.setQQNumber(rs.getString(6));
    consumerForm.setMainPage(rs.getString(7));
    consumerForm.setInterest(rs.getString(8));
    consumerForm.setEMail(rs.getString(9));
    consumerForm.setManageLevel(rs.getString(10));
    list.add(consumerForm);
    }
    } catch (SQLException e) {
    e.printStackTrace();
    } return list;
    }}各位帮忙看下,谢了
      

  3.   

    代码中有很多异常输出
    看下你控制台输出的是什么
    并且指出52行在哪里
    怀疑创建链接失败
      con = DriverManager.getConnection(url, userName, password); 
      

  4.   

    //对数据库的查询操作
        public ResultSet executeQuery(String sql) {
            ResultSet rs;
            try {
                if (con == null) {
                    creatConnection();
                }
                Statement stmt = con.createStatement();  //52行位置
                try {
                    rs = stmt.executeQuery(sql);
                } catch (SQLException e) {
                    System.out.println(e.getMessage());
                    return null;
                }
            } catch (SQLException e) {
                System.out.println(e.getMessage());
                System.out.println("executeQueryError!");
                return null;
            }
            return rs;
        }
      

  5.   

    con是空的,你导入数据库驱动包了吗?
      

  6.   

    知道什么叫调试吗?遇到问题应该先用IDE工具的调试功能,如果你不会,那穷人测试器你总该会吧,system.out.println你总该会吧,能解决的就不要来这问了
      

  7.   

    你可以用if(xx!=NULL)来解决这种问题ResultSet rs = connection.executeQuery(sql); 
    if(rs!=NULL),试一下。