我在程序中,写了
Statement st=null;
ResultSet rs1=null;
PreparedStatement pstat1=null;
String result1;
String[] tmp1;
int count1;
ResultSet rscount1=null;try
{   st=smgwpool.createStatement();
   rs1=st.executeQuery("select * from tb");
   rscount1=st.executeQuery("select count(*) as c from tb");   count1=rscount1.getInt("c");         /**************************/   tmp1=new String[count1];
       
   while(rs1.next())
   {   
     ...........
   }
}
catch(Exception e)
{
    System.out.println("big fail!");
    System.out.println("The error is:"+e);
}
然后通过编译,在运行时,却出现了如下错误:
big fail!
The error is:java.sql.SQLException: 未调用 ResultSet.next
经过测试是带/**************/那行有问题,但又不知哪里有错,报的错什么意思,望高手指教啊!!!  

解决方案 »

  1.   

    select count(*) 
    你为什么还要next?
      

  2.   

    我又在/*******************/的上面,加了
    rscount1.next();
    结果运行时错误是:
    big fail!
    The error is:java.lang.NullPointerException
    说是空指针,这到底是哪里错啊?请各位高手指点一二啊,谢谢了!!!
      

  3.   

    这不写着了吗?未调用ResultSet.next(),你试试
    while(rscount1.next()){
       count1=rscount1.getInt("c");   
    }
      

  4.   

    to gemouzhi(gemouzhi) :
    我定义了两个ResultSet对象啊,为的是一个获取记录集的个数,一个是为了取记录集里的数据啊。
      

  5.   

    select count(*) 
    你为什么还要next?因为返回的字符集。
      

  6.   

    我又在/*******************/的上面,加了
    rscount1.next();
    结果运行时错误是:
    big fail!
    The error is:java.lang.NullPointerException
    说是空指针,这到底是哪里错啊?请各位高手指点一二啊,谢谢了!!!
    ----
    rscount1.next();当然NullPointerException
      

  7.   

    Moves the cursor down one row from its current position. A ResultSet cursor is initially positioned before the first row; the first call to the method next makes the first row the current row; the second call makes the second row the current row, and so on. 
    ----
    有道理,那需要next();rscount1.next();应该没错
      

  8.   

    st=smgwpool.createStatement();
       rscount1=st.executeQuery("select count(*) as c from tb");
       rscount1。next();
       count1=rscount1.getInt("c");
       tmp1=new String(count1);
       rscount1。close();   rs1=st.executeQuery("select * from tb");       
       while(rs1.next())
       {   
         ...........
       }-------这个你看成吗?
      

  9.   

    to lcwlyl(网络幽灵) :
    谢谢啊!我这样试过了,问题解决了,但是运行时报错,
    big fail!
    The error is:java.lang.NullPointerException
    经过测试是那个
    while(rs1.next())
       {   
         ...........
       }
    有问题了,这个while(rs1.next)都没有进去,就是一进while就NullPointer了,这是怎么回事?难道和我运行两句select语句有关???
      

  10.   

    你试试把 rs1=st.executeQuery("select * from grade");  这句移到 while(rscount1.next()){
       count1=rscount1.getInt("c");   
    }下面,看看行吗?
      

  11.   

    一般executeQuery()不能连着用,等其中一个取完了,再用另一个。
      

  12.   

    上面情况是用createStatement,用prepareStatement()就可以。
      

  13.   

    to  gemouzhi(gemouzhi) :
    谢谢你!问题解决了!!!