寻求解决tomcat 运行 jsp 错误!!!
这是代码:<%@pagecontentType="text/html;charset=gb2312"%><%@pagelanguage="java"import="jav...
这是代码:
<%@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=****";
conn = DriverManager.getConnection( sConn );
//创建Statement对象
stmt = conn.createStatement();
//执行SQL语句
String query = "select * 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)
{
System.out.println("error occured!!");
}
finally
{
//释放数据库连接
rs.close();
stmt.close();
conn.close();
}
%>
</table>
</body>
</html>
root cause
java.lang.NullPointerException
org.apache.jsp.simpleDBAccess_jsp._jspService(simpleDBAccess_jsp.java:113)
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:384)
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)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs.
--------------------------------------------------------------------------------
Apache Tomcat/6.0.10 展开
<%@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=****";
conn = DriverManager.getConnection( sConn );
//创建Statement对象
stmt = conn.createStatement();
//执行SQL语句
String query = "select * 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)
{
System.out.println("error occured!!");
}
finally
{
//释放数据库连接
rs.close();
stmt.close();
conn.close();
}
%>
</table>
</body>
</html>
root cause
java.lang.NullPointerException
org.apache.jsp.simpleDBAccess_jsp._jspService(simpleDBAccess_jsp.java:113)
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:384)
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)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs.
--------------------------------------------------------------------------------
Apache Tomcat/6.0.10 展开
2个回答
展开全部
我用我的数据库和表改了一点点,可以运行的啊,你自己对着看看
<%@page language="java" contentType="text/html" pageEncoding="gbk"%>
<%@page import="java.sql.*" %>
<%
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
//载入MySQL的JDBC驱动类
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost/bbs?user=root&password=root";
conn = DriverManager.getConnection(url);
stmt = conn.createStatement();
String query = "select * from users";
rs = stmt.executeQuery(query);
%>
<html>
<head>
<title>JSP使用JDBC连接MySQL</title>
</head>
<body>
<table border=1 >
<tr bgcolor=gray>
<td>FirstName</td>
<td>LastName</td>
<td>NickName</td>
</tr>
<%
//循环操作返回的数据集
while (rs.next()) {
%>
<tr>
<td><%=rs.getString("name")%></td>
<td><%=rs.getString("password")%></td>
<td><%=rs.getString("sex")%></td>
</tr>
<%
}
} catch (Exception e) {
System.out.println("error occured!!");
} finally {
//释放数据库连接
rs.close();
stmt.close();
conn.close();
}
%>
</table>
</body>
</html>
<%@page language="java" contentType="text/html" pageEncoding="gbk"%>
<%@page import="java.sql.*" %>
<%
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
//载入MySQL的JDBC驱动类
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost/bbs?user=root&password=root";
conn = DriverManager.getConnection(url);
stmt = conn.createStatement();
String query = "select * from users";
rs = stmt.executeQuery(query);
%>
<html>
<head>
<title>JSP使用JDBC连接MySQL</title>
</head>
<body>
<table border=1 >
<tr bgcolor=gray>
<td>FirstName</td>
<td>LastName</td>
<td>NickName</td>
</tr>
<%
//循环操作返回的数据集
while (rs.next()) {
%>
<tr>
<td><%=rs.getString("name")%></td>
<td><%=rs.getString("password")%></td>
<td><%=rs.getString("sex")%></td>
</tr>
<%
}
} catch (Exception e) {
System.out.println("error occured!!");
} finally {
//释放数据库连接
rs.close();
stmt.close();
conn.close();
}
%>
</table>
</body>
</html>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询