为什么得不到记录集的结果???
<%@ page contentType="text/html;charset=GBK" language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.text.*" %>
<%@ page import="com.zwqk.*" %>
<jsp:useBean id="QueryBeanKp" class="com.zwqk.workPk" scope="page">
<jsp:setProperty name="QueryBeanKp" property="*"/>
</jsp:useBean>
<html>
<body>
<%
String kp = (String)request.getParameter("kp");
ResultSet rs = QueryBeanKp.get_kp(kp);
int recordNum = 0;
while(rs.next())
recordNum ++;
{
%>
<table border="1">
<tr>
<td width="50%" border="1">
<table>
<%
int n = (recordNum + 1)/2;
int i = 0;
while(i<n && rs.next())
out.println("Test 1......");//不加这个就什么也显示不了了!???
{
%>
<tr>
<td><input type="text" size="7" value="<%//=rs.getString(1)%>"></td>
<td><input type="text" size="25" value="<%//=rs.getString(2)%>"></td>
<td><input type="text" size="6" value="<%//=rs.getString(3)%>"></td>
<td><input type="text" size="4" value="<%//=rs.getString(4)%>"></td>
<td><input type="text" size="4" value="<%//=rs.getString("5")%>"></td>
</tr>
<%
i = i + 1;
}
%>
</table>
</td>
<td width="50%" border="1">
<table>
<%
while(rs.next())
out.println("Test 2......");//不加这个就什么也显示不了了!???
{
%>
<tr>
<td><input type="text" size="7" value="<%//=rs.getString(1)%>"></td>
<td><input type="text" size="25"value="<%//=rs.getString(2)%>"></td>
<td><input type="text" size="6" value="<%//=rs.getString(3)%>"></td>
<td><input type="text" size="4" value="<%//=rs.getString(4)%>"></td>
<td><input type="text" size="4" value="<%//=rs.getString(5)%>"></td>
</tr>
<%
}
%>
</table>
</td>
</tr>
</table>
<%
}
rs.close();
%>
</body>
</html>
而我用下面的代码却没有问题!这两个只是得到 rs 的方法不同而已!
<%@ page contentType="text/html;charset=GBK" language="java" %>
<%@ page import="java.sql.*,java.util.*,java.io.*,com.zwqk.*" %>
<html>
<body>
<%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=zwqk";
String user = "sa";
String password = "";
Connection conn = DriverManager.getConnection(url,user,password);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql = "select * from tblDdlr";
ResultSet rs = stmt.executeQuery(sql);
int recordNum = 0;
while( rs.next() )
recordNum++;
{
%>
<table width="100%" border="1">
<tr>
<td width="50%">
<table width="100%" border="1">
<%
rs.beforeFirst();
int n = (recordNum + 1)/2;
int i = 0;
while( i < n && rs.next() )
{
%>
<tr>
<td><%=rs.getString(1)%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getString(4)%></td>
<td><% out.println(i);%></td>
</tr>
<%
i = i + 1;
}
%>
</table>
</td>
<td width="50%">
<table width="100%" border="1">
<%
while( rs.next() )
{
%>
<tr>
<td><%=rs.getString(1)%></td>
<td><%=rs.getString(2)%></td>
<td><%=rs.getString(3)%></td>
<td><%=rs.getString(4)%></td>
<td><% out.println( (recordNum - n) + i ); %></td>
</tr>
<%
}
%>
</table>
</td>
</tr>
</table>
<%
}
%>
</body>
</html>
急等中请大家帮忙亚.......