jsp页面显示数据库表数据

在class.formname那里报错,错误提示语法错误,看不出来在哪啊,没错啊?

<%@ page language="java" contentType="text/html; charset=utf-8"

pageEncoding="utf-8"%>

<%@ page import="com.mysql.jdbc.Connection" %>
<%@ page import="com.mysql.jdbc.ResultSet" %>
<%@ page import="com.mysql.jdbc.Statement" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>图书清单</title>
<style type="text/css">
table {

border: 2px #CCCCCC solid;  
width: 360px;  

}

td,th {

height: 30px;  
border: #CCCCCC 1px solid;  

}
</style>
</head>
<body>
<%

    //驱动程序名   
    String driverName = "com.mysql.jdbc.Driver";  
    //数据库用户名   
    String userName = "root";  
    //密码   
    String userPasswd = "";  
    //数据库名   
    String dbName = "hibernate";  
    //表名   
    String tableName = "book";  
    //联结字符串   
    String url = "jdbc:mysql://localhost:3306/" + dbName + "?user="+ userName + "&password=" + userPasswd;  
    Class.forName("com.mysql.jdbc.Driver").newInstance();  
    Connection connection = (Connection)DriverManager.getConnection(url);  
 Statement statement = (Statement) connection.createStatement();  
 String sql = "SELECT * FROM " + tableName;  
 ResultSet rs = (ResultSet)statement.executeQuery(sql);  
%>  
<br>  
<br>  
<table align="center">  
    <tr>  
        <th>  
            <%  
                out.print("图书名称");  
            %>  
        </th>  
        <th>  
            <%  
                out.print("作者");  
            %>  
        </th>  
        <th>  
            <%  
                out.print("出版社");  
            %>  
        </th>  
        <th>  
            <%  
                out.print("出版日期");  
            %>  
        </th>  
        <th>  
            <%  
                out.print("类别");  
            %>  
        </th>  
    </tr>  

    <%  
        while (rs.next()) {  
    %>  
    <tr>  
        <td>  
            <%  
                out.print(rs.getString(1));  
            %>  
        </td>  
        <td>  
            <%  
                out.print(rs.getString(2));  
            %>  
        </td>  
        <td>  
            <%  
                out.print(rs.getString(3));  
            %>  
        </td>  
        <td>  
            <%  
                out.print(rs.getString(4));  
            %>  
        </td>  
         <td>  
            <%  
                out.print(rs.getString(5));  
            %>  
        </td>  
    </tr>  
    <%  
        }  
    %>  
</table>  
<div align="center">  
    <br> <br> <br>  
    <%  
        out.print("数据查询成功,恭喜你");  
    %>  
</div>  
<%  
    rs.close();  
    statement.close();  
    connection.close();  
%>  

</body>
</html>

MM们
浏览 793回答 3
3回答

慕标琳琳

学会debug,你会很受用的,浏览器用谷歌,f12,debug,后台用ide debug

神不在的星期二

.newInstance() 去掉,什么毛病.从哪抄的?
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java