我的一个用ms sql server 数据库连接池做的程序,其中的一个方法getAllMessages如下所示,当运行到该方法时,出现如下出错信息,主要的摘要如下:java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]ResultSet can not re-read row data for column 8.
      at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)如下为该方法程序:
public Collection getAllMessages(int pagesize, int page) {
// 创建数据库连接对象:
                Connection conn=null;
                Statement stmt=null;
                ResultSet rs=null;    try {
// 创建数据记录集对象:
                        conn=getConnection();
                       stmt=conn.createStatement(
                                ResultSet.TYPE_SCROLL_INSENSITIVE,
                              ResultSet.CONCUR_READ_ONLY);  // sql语句:
String sql = "select bbsitems.*,bbsitems1.item_id item_id1,bbsitems1.author replyer," + "bbsitems1.compose_date reply_latest_date from bbsitems "+ "inner join bbsitems bbsitems1 on bbsitems.item_id=" + "bbsitems1.fathers_id and bbsitems.latest_replication_id="+ "bbsitems1.item_id where bbsitems.is_origional = 1 " + "order by bbsitems.item_id desc  " ;

// 执行sql语句:
// 执行sql语句,返回一个记录集到rs:
rs = stmt.executeQuery(sql);
Collection c = new ArrayList();
BBSMsg msg = null;
                         while (rs.next()) {
msg = new BBSMsg();
                                msg.setAuthor(rs.getString("author"));
msg.setBrowsed_times(rs.getInt("browsed_times"));
msg.setFathers_id(rs.getInt("fathers_id"));
msg.setIs_origional(rs.getInt("is_origional"));
msg.setItem_content(rs.getString("item_content"));
int itemid = rs.getInt("item_id");
msg.setItem_id(itemid);
msg.setItem_title(rs.getString("item_title"));
msg.setLatest_replication_id(rs.getInt"latest_replication_id"));
msg.setReplyed_times(rs.getInt("replyed_times"));
msg.setStrCompose_date(rs.getString("compose_date"));
msg.setStrModify_date(rs.getString("modify_date"));
if (rs.getInt("item_id") == rs.getInt("item_id1")) {
msg.setLatest_replyer("");
msg.setStrLatest_reply_date("");
} else {
msg.setLatest_replyer(rs.getString("replyer"));
msg.setStrLatest_reply_date(rs.getString("reply_latest_date"));
}
msg.setLevel(0);
c.add(msg); Collection temp = getMessages(getFamilyLevel(itemid, 0));
if (temp != null) {
c.addAll(temp);
}
msg.setFace(rs.getInt("face"));
msg = null;
}
                      return c;
                      }catch (SQLException sqlExc) {
                                sqlExc.printStackTrace();
                                return null;
                        }
        finally
                  {closeResultSet(rs);
                  closeStatement(stmt);
                  closeConnection(conn);
                  }
               // return c;
                }

解决方案 »

  1.   

    stmt=conn.createStatement(                    ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);该这个创建流对象时候的参数具体参数网上查找
      

  2.   

    conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,                                      ResultSet.CONCUR_UPDATABLE);
      

  3.   

    你的程序比较乱 不看了
    给你翻译一下下面这句
    ResultSet can not re-read row data for column 8.
    ResultSet不能够重复(或者再一次)读取第8列数据
      

  4.   

    这两句导致的
    int itemid = rs.getInt("item_id");
    ...
    if (rs.getInt("item_id") == rs.getInt("item_id1")) 将后一句改为
    if (itemid == rs.getInt("item_id1")) 只能读一次,读取后,buffer就清空了
      

  5.   

    各位网友,您们好! 我个人觉得北极人讲得有些道理,即buffer 问题,但经进一步调试,当我改为显示同一库中的另一个表的字段时,则程序能顺利运行,不知什么原因 ?
    java.sql.SQLException: 
    [Microsoft][SQLServer 2000 Driver for JDBC]ResultSet can not re-read row data for 
    column 8.  at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)以下为该方法程序(简略版):
    public void getAllMessages(int pagesize, int page) { 
                    Connection conn=null;
                    Statement stmt=null;
                    ResultSet rs=null;
         try {  
                             conn=getConnection();
                            stmt=conn.createStatement(
                               ResultSet.TYPE_SCROLL_INSENSITIVE,
                               ResultSet.CONCUR_READ_ONLY);
                               String sql="select * from bbsitems" 
                rs = stmt.executeQuery(sql);  
                             while (rs.next()) {
                               System.out.println(rs.getString("author"));
                               System.out.println(rs.getInt("browsed_times"));
                               System.out.println(rs.getInt("fathers_id")); // 经跟踪,是这一列fathers_id出错.此段程序编译时不出错.
                               其余略.... }
          
                          }catch (SQLException sqlExc) {
                                    sqlExc.printStackTrace();
                                    return null;
                            }
            finally
                      {closeResultSet(rs);
                      closeStatement(stmt);
                      closeConnection(conn);
                      }
                     }