ResultSet Rs=stmt.executeQuery(sql);
Rs.next();//在这加一句
out.print(Rs.getInt("id"));

解决方案 »

  1.   

    这样是行了。可为什么我的留言本不行呢!?这是怎么回事?!这个的源程序上有Rs.next();
    啊。我还要怎么写啊?!<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" %>
    <html>
    <head>
    <title>留言本</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <link href="css/style" rel="stylesheet" type="text/css">
    </head>
    <jsp:useBean id="guestbook" class="guestbook.GuestBookJdbc" scope="page"/>
    <body bgcolor="#EBEBEB"><table width="776" border="0" align="center" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#FFFFFF">
      <tr> 
        <td height="28" align="center" bgcolor="#EBEBEB">留言本</td>
      </tr>
      <tr>
        <td height="24" align="center" bgcolor="#EBEBEB"><a href="add.jsp">添加留言</a> 
          返回主页 站长邮件 留言系统 </td>
      </tr>
    </table>
    <%
      Connection Conn=guestbook.GetConn();
      Statement stmt=Conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
      String sql="select * from Guestbook order by id DESC";
      ResultSet Rs=stmt.executeQuery(sql);
      int intPageSize; //一页显示的记录数 
      int intRowCount; //记录总数 
      int intPageCount; //总页数 
      int intPage; //待显示页码 
      String  strPage; 
      int i; 
      
    //设置一页显示的记录数 
     intPageSize = 6; //取得待显示页码 
    strPage = request.getParameter("page"); 
    if(strPage==null){//表明在QueryString中没有page这一个参数,此时显示第一页数据 
      intPage = 1; 
      } else{//将字符串转换成整型 
    intPage = java.lang.Integer.parseInt(strPage); 
    if(intPage< 1) intPage = 1; 

    //获取记录总数 
    Rs.last(); 
    intRowCount = Rs.getRow(); 
    //记算总页数 
    intPageCount = (intRowCount+intPageSize-1) / intPageSize; 
    //调整待显示的页码 
    if(intPage >intPageCount) intPage = intPageCount; 
    if(intPageCount >0){ 
    //将记录指针定位到待显示页的第一条记录上 
    Rs.absolute((intPage-1) * intPageSize+1); 
    //显示数据 
    i = 0; 
    while(i< intPageSize && !Rs.isAfterLast()){ 
    %>
    <table width="776" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
      <tr bgcolor="#EBEBEB"> 
        <td width="143" height="25" align="center">姓名:<%=Rs.getString("username")%></td>
        <td width="100" align="center"><a href="<%=Rs.getString("url")%>">主页</a> </td>
        <td width="100" align="center"><a href="mailto:<%//Rs.getString("email")%>">邮件</a> </td>
        <td width="100" align="center">QQ :<%=Rs.getString("qq")%></td>
        <td width="100" align="center">
    <a href="reinfo.jsp?id=<%out.print(Rs.getInt("id"));%>">回复</a></td>
        <td width="100" align="center"><a href="del.jsp?id=<%//id%>">删除</a></td>
    ///这个地方如何取得id?!!?
      </tr>
      <tr bgcolor="#EBEBEB"> 
        <td height="42" rowspan="3" align="center">&nbsp;</td>
        <td height="17" colspan="5">留言内容:</td>
      </tr>
      <tr> 
        <td height="31" colspan="5" bgcolor="#EBEBEB"> 
          <%String content=Rs.getString("content");
        if(content!="")
    {
    out.print(content);
    }%>
        </td>
      </tr>
      <tr> 
        <td height="22" colspan="5" bgcolor="#EBEBEB">回复内容: 
          <%String recontent=Rs.getString("recontent");
        if(recontent!=null)
    {
    out.print(recontent);
    }%>
        </td>
      </tr>
    </table>
    <% 
      Rs.next(); 
       i++; 
      } 
    %> 
    <table width="776" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
      <tr>
        <td height="22" align="center" bgcolor="#EBEBEB">第<%=intPage%>页 共<%=intRowCount%>条记录/共<%=intPageCount%>页 
          <%   }
      else{
               out.print("目前还没有内容!");
      }%>
        </td>
      </tr>
    </table>
    </body>
    </html>
      

  2.   

    出现什么问题了
    其实你直接while(rs.next())就行了,如果数据到头了会返回false的
      

  3.   

    同意楼上的,直接用while作循环就可以了!
      

  4.   

    ///这个地方如何取得id?!!?同一条ResultSet的getXXXX()方法好像对同一个字段不能重复使用,所以最好用int id=Rs.getInt("id");然后再访问id这个变量为好.
      

  5.   

    加上rs.next(),
    要修改数据集的指针,才能取到你想要的记录