2021-09-09 jsp查询数据库的数据

<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.PreparedStatement" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/9/9
  Time: 10:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户列表</title>
    <style type="text/css">
        #user_table{
            width: 80%;
           border-collapse: collapse;
            text-align: center;
        }

    </style>
</head>
<body>
    <table border="1" id="user_table">
        <tr>
            <th>编号</th>
            <th>姓名</th>
            <th>账号</th>
            <th>密码</th>
            <th>性别</th>
            <th>年龄</th>
            <th>生日</th>
            <th>创建时间</th>
        </tr>
                                               //jdbc:mysql://localhost:3306/jsd2107?useUnicode=true&characterEncoding=utf-8&useSSL=false
    <%                                         //jdbc:mysql://localhost:3306/jsd2107?useUnicode=true&characterEncoding=utf-8&useSSl=false
        Class.forName("com.mysql.jdbc.Driver");//jdbc:mysql://localhost:3306/jsd2107?useUnicode=true&characterEncoding=utf-8&useSSL=false
        Connection con =  DriverManager.getConnection("jdbc:mysql://localhost:3306/jsd2107?useUnicode=true&characterEncoding=utf-8&useSSL=false","root","root");
        PreparedStatement pst =  con.prepareStatement("select * from user");
        ResultSet rs = pst.executeQuery();

        while (rs.next()){
    %>
        <tr>
            <td><%=rs.getInt("id")%></td>
            <td><%=rs.getString("name")%></td>
            <td><%=rs.getString("username")%></td>
            <td><%=rs.getString("password")%></td>
            <td><%=rs.getInt("sex")%></td>
            <td><%=rs.getInt("age")%></td>
            <td><%=rs.getDate("birthday")%></td>
            <td><%=rs.getTime("create_time")%></td>
        </tr>


    <%

        }
        rs.close();
        pst.close();
        con.close();


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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值