<%--
Created by IntelliJ IDEA.
User: luffy
Date: 2021/8/3
Time: 23:49
To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.sql.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<!-- 连接数据库必须将“java.sql”导入 -->
<!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>
</head>
<script type="text/javascript">
function deleteRow(r)
{
var i=r.parentNode.parentNode.rowIndex;
document.getElementById('myTable').deleteRow(i);
}
</script>
<body>
<center>
<a href=>添加</a>
<table id='myTable' border="1" align="center" width="50%">
<tr>
<th>id</th>
<th>账号</th>
<th>密码</th>
<th>功能</th>
</tr>
<!-- 注意:<% %>中的是脚本语言 -->
<%
Class.forName("com.mysql.cj.jdbc.Driver");
//加载驱动
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/dbc?characterEncoding=utf-8","root","123456");
//上面两句是与数据库建立连接
Statement stmt=conn.createStatement();
//stmt拥有执行sql语句的方法
String sql="select * from student";
ResultSet rs=stmt.executeQuery(sql);
//执行s语句,得到的rs指向所查数据的开头
//下述语句是将查到的数据展示到页面,用到html内容要用
//out.println("<table align='center' border='1px' cellpadding='20' cellspacing='0' class='a'>"+"<tr><th> id:</th> <th> 账号:</th> <th> 密码:</th> <th>功能: </th> </tr> </table> ");
Map map = new HashMap();
while(rs.next()) {
int a =Integer.valueOf( rs.getInt(1));
String b = rs.getString(2);
String c = rs.getString(3);
map.put("in",a);
map.put("name",b);
map.put("pass",c);
for(int j=0;j<=0; j++){
out.print("<tr>"+
"<td>"+ map.get("in")+"</td> " +
"<td>"+ map.get("name")+"</td> " +
"<td>"+ map.get("pass")+"</td> " +
"<td><input type='button' value='Delete' onclick='deleteRow(this)'> </td>"+
"</tr>");
}
out.print(" </tr> "+"<br>");
//数据库中存的id不需要展示,但在其修改和删除的链接中要用
}
out.print("</table>");
//由内向外一层层关闭
rs.close();
stmt.close();
conn.close();
%>
</table>
</center>
</body>
</html>
```sql
//数据库
CREATE TABLE `student` (
`id` int(0) NOT NULL AUTO_INCREMENT,
`username` varchar(100) NOT NULL,
`password` varchar(40) NOT NULL,
PRIMARY KEY (`id`)
) ;
insert into student()VALUES(1,'123','123');
select *from student;
```