zoukankan      html  css  js  c++  java
  • JSP页面输出数据库表格

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>主页测试数据库连接</title>
    </head>
    <body>
    <%
    //注册数据库驱动
    Class.forName("com.mysql.jdbc.Driver");
    //获取数据库连接
    Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test01", "root", "root");
    //创建statement
    Statement stmt = conn.createStatement();
    //执行查询
    String sql = "select * from userinfo";
    ResultSet rs = stmt.executeQuery(sql);
    %>
    <table bgcolor="#9999dd" border="1" width="300">
    <tr>
    <th>序号:</th>
    <th>姓名:</th>
    <th>年龄:</th>
    </tr>
    <%

    //遍历结果集
    while(rs.next())
    {%>
    <!-- <tr>
    <th>序号:</th>
    <th>姓名:</th>
    <th>年龄:</th>
    </tr> -->
    <tr>
    <!-- 输出结果集 -->
    <td><%=rs.getString(1) %></td>
    <td><%=rs.getString(2) %></td>
    <td><%=rs.getString(3) %></td>
    </tr>
    <%}
    %>

    </table>
    </body>
    </html>

    其中标红的代码注释掉了,具体情况看运行截图:

    就是那段代码加的位置不对,导致这样的结果发生

    博客园密码:yrz@zx1314

  • 相关阅读:
    python challenge level 2
    python challenge level1
    近期很忙
    python challenge level 3
    链 小实验
    结构体小小应用
    结构体 弄成绩统计比较好
    HTC学习
    WEBFX XTREE学习笔记
    向dataset中添加一行记录,老是忘了,记下来
  • 原文地址:https://www.cnblogs.com/yaoruozi/p/8192933.html
Copyright © 2011-2022 走看看