详细代码如下:
************************
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>测试连接数据库</title>
</head>
<body>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/corejava", "root", "123");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from jdbctest");
%>
<table>
<%
while (rs.next()) {
%>
<tr>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getString(4)%></td>
<td><%=rs.getString(5)%></td>
<td><%=rs.getString(6)%></td>
<td><%=rs.getString(7)%></td>
</tr>
<%
}
%>
</table>
</body>
</html>
****************************
报错如下:
********************
org.apache.jasper.JasperException: Exception in JSP: /j2eetest/mysql.jsp:10 7: </head> 8: <body> 9: <% 10: Class.forName("com.mysql.jdbc.Driver"); 11: Connection conn = DriverManager.getConnection( 12: "jdbc:mysql://localhost:3306/corejava", "root", "123"); 13: Statement stmt = conn.createStatement(); Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
请高手指点指点,在线等