<%@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)
jsp连接数据库一直报错,求帮忙看下,谢谢
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
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); }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 uniapp实现如下图的图表功能
- ¥15 u-subsection如何修改相邻两个节点样式
- ¥30 vs2010开发 WFP(windows filtering platform)
- ¥15 服务端控制goose报文控制块的发布问题
- ¥15 学习指导与未来导向啊
- ¥15 求多普勒频移瞬时表达式
- ¥15 如果要做一个老年人平板有哪些需求
- ¥15 k8s生产配置推荐配置及部署方案
- ¥15 matlab提取运动物体的坐标
- ¥15 人大金仓下载,有人知道怎么解决吗