<span style="font-size:12px;"><span style="font-size:14px;">
<%@ page language="java" import="java.util.*,java.sql.*,java.io.*" %>
<%@ page contentType="text/html;charset=utf-8"%>
<html>
<head>
<title>查询数据库数据</title>
<style type="text/css">
table {
border: 2px #CCCCCC solid;
width: 360px;
}
td,th {
height: 30px;
border: #CCCCCC 1px solid;
}
</style>
</head>
<body>
<%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url="jdbc:microsoft:sqlserver://localhost:1433;Database=newStandard2012.dbo";
Connection con=DriverManager.getConnection(url,"sa","newu");
Statement stmt=con.createStatement();
String sql="select id,line_no,DateTime,alarm_class,uid,m1,recipe_name,recipe_code from newuStandard2012.dbo.newu_log_alarm";
//,line_no,alarm_class,uid
ResultSet rs=stmt.executeQuery(sql);
%>
<br>
<br>
<table align="center">
<tr>
<th>
<%
out.print("ID");
%>
</th>
<th>
<%
out.print("日期");
%>
</th>
<th>
<%
out.print("机台号");
%>
</th>
<th>
<%
out.print("班次");
%>
</th>
<th>
<%
out.print("登录用户");
%>
</th>
<th>
<%
out.print("备用");
%>
</th>
<th>
<%
out.print("配方名称");
%>
</th>
<th>
<%
out.print("配方编号");
%>
</th>
</tr>
<%
while (rs.next()) {
%>
<tr>
<td>
<%
out.print(rs.getString(1));
%>
</td>
<td>
<%
out.print(rs.getString(2));
%>
</td>
<td>
<%
out.print(rs.getString(3));
%>
</td>
<td>
<%
out.print(rs.getString(4));
%>
</td>
<td>
<%
out.print(rs.getString(5));
%>
</td>
<td>
<%
out.print(rs.getString(6));
%>
</td>
<td>
<%
out.print(rs.getString(7));
%>
</td>
<td>
<%
out.print(rs.getString(8));
%>
</td>
</tr>
<%
}
%>
</table>
<div align="center">
<br> <br> <br>
<%
out.print("数据查询成功,恭喜你");
%>
</div>
<%
rs.close();
stmt.close();
con.close();
%>
</body>
</html>
</span><span style="font-size:24px;color: rgb(255, 0, 0);">
</span></span>
各位哥哥姐姐们,谁知道从while(rs.next){}之后怎么用for循环打印出来,麻烦给写一下代码
看到这个 我也是醉了 rs.next()就是一条数据一条数据的获取 你想for循环什么
虽然2年没写java,但你这写法,哭了,后台去得到一个List,保存到Session,Cookie,这些对象里面,再在后台遍历,就ok了,好像还有个EL表达式
<% while (rs.next()) { %> <tr> <% for(int i=1;i<9;i++){ %> <td> <% out.print(rs.getString(i)); %> </td> <% } %> </tr> <% } %>