标签:
利用SQL Server查询数据,并把所有数据显示在页面上。
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@page import="jdbc.sqlServer"%> <%@page import="java.sql.Connection"%> <%@page import="java.sql.Statement"%> <%@page import="java.sql.ResultSet"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP ‘LinDao.jsp‘ starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <!-- 查询管理员信息 --> <div> <table border=1px style="width:500px;height:200px;text-align:center;margin: 0 auto;margin-top:0px"> <div style="width:500px;height:40px;border:1px solid red;margin:0 auto;text-align:center;margin-top:60px;background:#fff;margin-top:-2px"> <font color="red" font-weight="bold">管理员信息</font> </div> <tr style="background:red"> <td>编号</td> <td>姓名</td> <td>元宝数</td> <td>删除</td> </tr> <% //引用连接数据库方法 sqlServer sq1=new sqlServer(); //得到数据库连接 Connection con1 = sq1.getConnection(); //编写sql语句 String sql1="select * from Admin"; //得到数据库对象操作 Statement st1=con1.createStatement(); // 得到查询的结果 ResultSet rs1 = st1.executeQuery(sql1); while(rs1.next()){ %> <tr> <td> <%out.print(rs1.getInt(1) + "\t"); %></td> <td> <%out.print(rs1.getString(2) + "\t"); %></td> <td> <%out.println(rs1.getInt(3)+ "\t"); %></td> <td> <a href="time.jsp?id=<%out.print(rs1.getInt(1) + "\t"); %>">删除</a></td> </tr><% } //释放资源 sq1.ShiFang(rs1,st1,con1); %> </table> </div> </body> </html>
标签:
原文地址:http://www.cnblogs.com/wlx520/p/4501654.html