Topic: 问一个关于ResultSet的问题

  Print this page

1.问一个关于ResultSet的问题 Copy to clipboard
Posted by: dwju
Posted on: 2003-08-07 09:49

为什么数据库中没有记录的时候,使用ResultSet对象的isAfterLast()方法得出的结构却是FALSE,如果这样,我想判断一个ResultSet是否到最后应该怎么判断呢?郁闷!!!

2.Re:问一个关于ResuleSet的问题 [Re: dwju] Copy to clipboard
Posted by: dwju
Posted on: 2003-08-07 16:13

各位老大,有没有人会啊!!!

3.Re:问一个关于ResuleSet的问题 [Re: dwju] Copy to clipboard
Posted by: dwju
Posted on: 2003-08-07 16:34

人气好象不是太好啊!
晕~!
俺已经解决了!

4.Re:问一个关于ResuleSet的问题 [Re: dwju] Copy to clipboard
Posted by: ditty
Posted on: 2003-08-07 16:40

用next()方法就行了呀?何必?

5.Re:问一个关于ResuleSet的问题 [Re: dwju] Copy to clipboard
Posted by: dwju
Posted on: 2003-08-07 16:44

俺需要判断啊,不是做记录循环的……:(

6.Re:问一个关于ResuleSet的问题 [Re: dwju] Copy to clipboard
Posted by: why
Posted on: 2003-08-08 11:35

dwju wrote:
俺需要判断啊,不是做记录循环的……:(


ditty is right, next() is good enough for 判断... unless you meant something else.

by the way, how do you 解决.
please share your experience with everybody.

7.Re:问一个关于ResultSet的问题 [Re: dwju] Copy to clipboard
Posted by: dwju
Posted on: 2003-08-09 16:06

OK!星期一我贴上我的解决方法

8.Re:问一个关于ResultSet的问题 [Re: dwju] Copy to clipboard
Posted by: dwju
Posted on: 2003-08-12 16:28

<%@ page contentType="text/html; charset=GBK"
import="java.sql.*"
%>

<%
String theType = request.getParameter("setType");
String theStr = "产品展示";
if(theType.equals("zzcp")) theStr="最新产品";
if(theType.equals("cxcp")) theStr="促销产品";
if(theType.equals("rxcp")) theStr="热销产品";
%>
<jsp:useBean id="bean" scope="page" class="gcwd.DBConnection"/>
<jsp:useBean id="strBean" scope="page" class="gcwd.StringBean"/>
<%
int rowCount=0;
int intPage = 1;
int pageCount =1;
int pageSize =0;
int j =1;
String query="";
if(bean.dbConnection())
{
  /********************************************************
  *这里根据前面传来不同的值,来判断SQL语句
  *然后再执行查询,计算总行数和总的页数
  ********************************************************/
  if(theType.equals("zzcp"))
    query = "select top 100 spbm,spmc,spxh,jjsx,sbmc,jhdj,lsdj from kc_spzl order by czrq";
  if(theType.equals("cxcp"))
    query = "select spbm,spmc,spxh,jjsx,sbmc,jhdj,lsdj from kc_spzl";
  if(theType.equals("rxcp"))
    query = "select top 100 spbm,spmc,spxh,jjsx,sbmc,jhdj,lsdj from kc_spzl order by xxsl";
  ResultSet resultset = bean.executeQuery(query);
  //out.println(query);
  if(!resultset.isAfterLast())
  {
    resultset.last();
    rowCount = resultset.getRow();

    intPage = 1;
    //转化接收到的页面信息
    String strPage = request.getParameter("page");
    if(strPage==null)
    {
      intPage=1;
    }
    else
    {
      intPage = java.lang.Integer.parseInt(strPage);
      if(intPage<1) intPage=1;
    }

    pageSize = 13;

    pageCount = 0;
    //判断总页数,如果整除,则为整除结果,否则,就加一
    if(rowCount / pageSize==0)
      pageCount = rowCount / pageSize;
    else
      pageCount = rowCount / pageSize + 1;
    //如果显示结果不够一页,则在将每页显示记录数设置为总记录数
    if(rowCount < pageSize) pageSize = rowCount+1;
    if(intPage>pageCount) intPage=pageCount;
    j=(intPage-1)*pageSize+1;

  }
%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <link rel="stylesheet" href="css\css.css" type="text/css">
  </head>

  <body bgcolor="#FFFFFF" text="#000000" scroll=no>
    <table width=620 border="0" cellspacing="0" cellpadding="0" bgcolor="#E1E1E1" class="frmBox" align="center">
      <tr>
      <td bgcolor="#003399" height="20"></td>
      </tr>
      <tr>
      <td bgcolor="#999999" align=center>
        <table width="100%" border="0" cellspacing="0" cellpadding="1">
        <tr>
        <td rowspan="2" align="center" width="16%"><img src="img/001.gif" width="32" height="32"></td>
        <td width="84%"><font color="#FFFFFF" size="+1"><b>产品展示</b></font></td>
        </tr>
        <tr>
        <td width="84%"><font color="#FFFFFF">-------<%out.println(theStr);%>

        </font></td>
        </tr>
        </table>
      </td>
      </tr>
      <tr bgcolor="#E1E1E1" height=20><td></td></tr>
      <tr><td align="center">
      <table width=615>
        <tr>
      <td align="left"> </td>
        </tr>
      </table>

<table width=615 border="0" cellspacing="1" cellpadding="0" style="border:2 inset;line-height:3.0" bgcolor="#CCCCCC" >
   <tr bgcolor="#E1E1E1">
<td width=10% class="ed_btnStyle"><Strong>编号</strong></td>
<td width=25% class="ed_btnStyle"><Strong>名称</strong></td>
<td width=10% class="ed_btnStyle"><Strong>型号</strong></td>
<td width=10% class="ed_btnStyle"><Strong>商品规格</strong></td>
<td width=15% class="ed_btnStyle"><Strong>生产厂家</strong></td>
<td width=10% class="ed_btnStyle"><Strong>配送价</strong></td>
<td width=10% class="ed_btnStyle"><Strong>零售价</strong></td>
<td width=10% class="ed_btnStyle"><Strong>详细信息</strong></td>
</tr>
<%
/***********************************************************
*利用前面求出的pageCount来为查询叶面分页
* 注意,后面翻页的时候,注意传递不同的查询类型值
***********************************************************/
    int i=0;
    resultset.absolute(j);
    while(i < pageSize && !resultset.isAfterLast())
    {
      String changeSpbm=resultset.getString("spbm");
%>
  <tr bgcolor="#FFFFFF">
<td width=10% class="ed_btnStyle"><%=resultset.getString("spbm")%></td>
<td width=25% class="ed_btnStyle"><%=strBean.changeString(resultset.getString("spmc"),0,11)%></td>
<td width=10% class="ed_btnStyle"><%=resultset.getString("spxh")%></td>
<td width=10% class="ed_btnStyle"><%=strBean.changeString(resultset.getString("jjsx"),0,6)%></td>
<td width=15% class="ed_btnStyle"><%=strBean.changeString(resultset.getString("sbmc"),0,6)%></td>
<td width=10% class="ed_btnStyle"><%=resultset.getString("jhdj")%></td>
<td width=10% class="ed_btnStyle"><%=resultset.getString("lsdj")%></td>
<td width=10% class="ed_btnStyle"><a href="list.jsp?changeValue=<%=changeSpbm%>">详细信息</a></td>
     </tr>
<%
      i = i + 1;
      resultset.next();
}  //while结束
}
%>
</table>
   <table width=100%>
     <tr>
      <td width="30%">
        第<%=intPage%>页/共<%=pageCount%>页
      </td>
      <td width="70%" align="right">
        <%if(intPage!=1){%>
        <a href="cpzs.jsp?page=1&setType=<%=theType%>">首页</a>
        <%
        }
        else
        {
          out.print("首页");
        }%>
        <%if(intPage>1){%>
        <a href="cpzs.jsp?page=<%=intPage-1%>&setType=<%=theType%>">上一页</a>
        <%
        }
        else
        {
          out.print("上一页");
        }%>
        <%if(intPage < pageCount){%>
        <a href="cpzs.jsp?page=<%=intPage+1%>&setType=<%=theType%>">下一页</a>
        <%
        }
        else
        {
          out.print("下一页");
        }%>
        <%if(intPage!=pageCount){%>
        <a href="cpzs.jsp?page=<%=pageCount%>&setType=<%=theType%>">尾页</a>
        <%
        }
        else
        {
          out.print("尾页");
        }%>
      </td>
    </tr>
   </table>
</td>
</tr>
    </table>
  </body>
</html>

9.Re:问一个关于ResultSet的问题 [Re: dwju] Copy to clipboard
Posted by: redmiddle
Posted on: 2003-08-13 11:42

没有任何记录.又怎么可能有afterLast()了.你是resultSet的概念错误啦.
其实判断有没有到最后可以用isLast()就好了.


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923