我在程序中,写了
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
经过测试是带/**************/那行有问题,但又不知哪里有错,报的错什么意思,望高手指教啊!!!
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
经过测试是带/**************/那行有问题,但又不知哪里有错,报的错什么意思,望高手指教啊!!!
你为什么还要next?
rscount1.next();
结果运行时错误是:
big fail!
The error is:java.lang.NullPointerException
说是空指针,这到底是哪里错啊?请各位高手指点一二啊,谢谢了!!!
while(rscount1.next()){
count1=rscount1.getInt("c");
}
我定义了两个ResultSet对象啊,为的是一个获取记录集的个数,一个是为了取记录集里的数据啊。
你为什么还要next?因为返回的字符集。
rscount1.next();
结果运行时错误是:
big fail!
The error is:java.lang.NullPointerException
说是空指针,这到底是哪里错啊?请各位高手指点一二啊,谢谢了!!!
----
rscount1.next();当然NullPointerException
----
有道理,那需要next();rscount1.next();应该没错
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())
{
...........
}-------这个你看成吗?
谢谢啊!我这样试过了,问题解决了,但是运行时报错,
big fail!
The error is:java.lang.NullPointerException
经过测试是那个
while(rs1.next())
{
...........
}
有问题了,这个while(rs1.next)都没有进去,就是一进while就NullPointer了,这是怎么回事?难道和我运行两句select语句有关???
count1=rscount1.getInt("c");
}下面,看看行吗?
谢谢你!问题解决了!!!