程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> 數據庫-JSP程序之前一台電腦可以運行,但是另一台電腦就不行

數據庫-JSP程序之前一台電腦可以運行,但是另一台電腦就不行

編輯:編程綜合問答
JSP程序之前一台電腦可以運行,但是另一台電腦就不行

程序如下

 5.public class DBConBean {

    private static final String URL = "jdbc:mysql://127.0.0.1:3306/bank";
    private static final String USER = "root";
    private static final String PASSWORD = "";

    private static Connection conn = null;
    Statement stat = null;
    PreparedStatement pstat = null;
    ResultSet rs = null;
    int rs_1 = 0;

    public static Connection getConnection() {
        try {
            //加載驅動程序
            Class.forName("com.mysql.jdbc.Driver");
            //獲得數據庫連接
            conn = DriverManager.getConnection(URL, USER, PASSWORD);
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return conn;
    }

    public ResultSet query (String sql) {
        try {
            conn = getConnection();
37.         stat = conn.createStatement();
            rs = stat.executeQuery(sql);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return rs;
    }

報錯如下
type Exception report

message java.lang.NullPointerException

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

exception

org.apache.jasper.JasperException: java.lang.NullPointerException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:477)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

java.lang.NullPointerException
com.zy.dao.DBConBean.query(DBConBean.java:37)
org.apache.jsp.Page_005fuser_jsp._jspService(Page_005fuser_jsp.java:161)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.65 logs.
求大神解答

最佳回答:


斷點一下看看conn是不是為空,如果為空就可以往2個方向找錯誤,1,有沒有jdbc的驅動包,2、用戶名密碼和URL是不是對,你這裡可以在本地用數據庫的客戶端看看能不能臉上,有沒有這個數據庫。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved