当前位置: 代码迷 >> Java Web开发 >> tomcat 导入程序包 运行报错,怎么改,求教
  详细解决方案

tomcat 导入程序包 运行报错,怎么改,求教

热度:795   发布时间:2013-04-26 08:52:19.0
tomcat 导入程序包 运行报错,怎么改,求教
本人用的是sql  server 2005     
jdbcconnection.java文件内容如下   
package com.wy.tool;

import java.sql.*;

public class JDBConnection {
    private final String url = "jdbc: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.sqlserver.jdbc.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;
    }


}


报错如下:
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

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:637)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.36 logs.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.36
搜索更多相关主题的帖子: sqlserver  tomcat  localhost  password  private  

----------------解决方案--------------------------------------------------------
先看你本地数据库有没有db_BlodMay 这个库
JDBConnection.java:52 在看有没有错
在看 ConsumerDao.java:98 有没有错

都没有错 在看你的SQL2005有没有开启服务

----------------解决方案--------------------------------------------------------
你按照提示的错误查找错误行,估计不是因为你的配置问题。
首先确定你不是在启动服务的时候就报错,也就是说连接到了数据库,只是在操作的时候出现问题
其次,根据错误信息准确定位,报错位置,建议学会使用断点查找
----------------解决方案--------------------------------------------------------
  相关解决方案