<%@page contentType="text/html;charset=gb2312" %>
<%@page language="java" import="java.sql.*" %>
<%
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
try
{
//载入MySQL的JDBC驱动类
Class.forName("com.mysql.jdbc.Driver");
//获得数据库的连接
String sConn="jdbc:mysql://localhost/ch01?user=root&password=880801";
conn=DriverManager.getConnection(sConn);
//创建Statement对象
stmt=conn.createStatement();
//执行SQL语句
String query="slect * from user_info";
rs=stmt.executeQuery(query);
%>
<html>
<head>
<title>JSP使用JDBC连接MySQL</title>
</head>
<body>
<table border=1 cellspacing=0 cellpadding=0>
<tr bgcolor=gray>
<td>FirstName</td>
<td>LastName</td>
<td>NickName</td>
</tr>
<%
//循环操作返回的数据集
while(!rs.isLast())
{
rs.next();
%>
<tr>
<td><%=rs.getString("first_name")%></td>
<td><%=rs.getString("last_name")%></td>
<td><%=rs.getString("nick_name")%></td>
</tr>
<%
}
}
catch(Exception e)
{
}
finally
{
//释放数据库连接
rs.close();
stmt.close();
conn.close();
}
%>
</table>
</body>
</html>
下面是报错信息:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Exception in JSP: /sDBA.jsp:63
60: finally
61: {
62: //释放数据库连接
63: rs.close();
64: stmt.close();
65: conn.close();
66: }
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.lang.NullPointerException
org.apache.jsp.sDBA_jsp._jspService(sDBA_jsp.java:113)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.26 logs.
跪求org.apache.jasper.JasperException的解决方法
答案:2 悬赏:0 手机版
解决时间 2021-02-27 10:27
- 提问者网友:無理詩人
- 2021-02-26 21:32
最佳答案
- 五星知识达人网友:往事埋风中
- 2021-02-26 22:33
在finally中close时要做判断
//释放数据库连接
if(rs!=null) rs.close();
if(stmt!=null) stmt.close();
if(conn!=null) conn.close();
//释放数据库连接
if(rs!=null) rs.close();
if(stmt!=null) stmt.close();
if(conn!=null) conn.close();
全部回答
- 1楼网友:毛毛
- 2021-02-26 23:33
好像是你的index.jsp报错了。去tomcat路径下work\catalina\localhost下找到你的项目目录,再进到org\apache\jsp下,看看index_jsp.java的86行写的是什么?引入报表了?
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯