<%@ 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>
2021-09-09 jsp查询数据库的数据
最新推荐文章于 2023-06-04 18:09:33 发布