用SQL Server查询所有数据并显示

发表于:2015-5-18 10:09

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:祥龙技术博客园    来源:51Testing软件测试网采编

  利用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>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号