u010259017 2015-04-19 12:12 采纳率: 60%
浏览 1848
已采纳

jsp连接数据库一直报错,求帮忙看下,谢谢

<%@page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="java.sql.*"%>
<html>
<body>
<%
    String tablename=request.getParameter("tablename");
    if(tablename==null) tablename="";
    byte[] b=tablename.getBytes("ISO-8859-1"); tablename=new String(b);
    out.println(tablename);

    final String DRIVER = "org.gjt.mm.mysql.Driver";
    final String DURL = "jdbc:mysql://localhost:3306/application";
    final String DUSER = "root";
    final String DPASS = "594daidai";
        Connection conn = null;     
        try{
            Class.forName(DRIVER);
        }catch(ClassNotFoundException e){
            e.printStackTrace();
        }
        try{
            conn = DriverManager.getConnection(DURL,DUSER,DPASS);
        }catch(SQLException e){
            e.printStackTrace();
        }   
        out.println(conn);      
        try{
            conn.close();       
        }catch(SQLException e){
            e.printStackTrace();
        }
%>
</body>
</html>





 HTTP Status 500 -

type Exception report

message

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

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /bookMinage/docreatetable.jsp at line 28

25:         }   
26:         out.println(conn);      
27:         try{
28:             conn.close();       
29:         }catch(SQLException e){
30:             e.printStackTrace();
31:         }


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause

java.lang.NullPointerException
    org.apache.jsp.bookMinage.docreatetable_jsp._jspService(docreatetable_jsp.java:82)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)  
  • 写回答

10条回答 默认 最新

  • zx8813443 2015-04-21 01:58
    关注

    conn.close(); 这句报空指针, 说明你之前的连接没有获取到,肯定是上面的语句抛了异常
    建议你按照如下代码调试,就可以找到问题所在了,有可能是没有找到驱动的JAR,有可能用户名密码不对,具体看异常打印吧。

        Connection conn = null;     
        try{
            Class.forName(DRIVER);
            conn = DriverManager.getConnection(DURL,DUSER,DPASS);
            out.println(conn);      
            conn.close();       
        }catch(ClassNotFoundException e){
            out.println(e);
        }catch(SQLException e){
            out.println(e);
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(9条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀