Topic: 我都要发疯了,为什么ResultSet在使用第7次时会突然抛出异常!

  Print this page

1.我都要发疯了,为什么ResultSet在使用第7次时会突然抛出异常! Copy to clipboard
Posted by: siberia
Posted on: 2004-10-07 22:14

下面这段程序:

String data = "-";
while(rs.next()) {
%>
<tr>
<%
for(i=0;i<count;i++)
{
System.err.println(i);

if(i == 5)
{
float temp = rs.getFloat(i+1);
data = Float.toString(db.SellPrice(temp));
}
else
{
data = rs.getString(i+1);
if(data==null)
data = "-";
}
System.err.println(data);
%>
<td><%=data%></td>
<%
}
}


下面出错提示,中间包含err.println的数出结果:
0

1000232

1

手术刀柄

2

3号-200MM

3

24

4



5

16.15

6

StandardWrapperValve[debugjsp]: Servlet.service() for servlet debugjsp threw exception

java.lang.NullPointerException

java.lang.NullPointerException

  at oracle.jdbc.driver.ScrollableResultSet.getCachedDatumValueAt(ScrollableResultSet.java:1307)

  at oracle.jdbc.driver.ScrollableResultSet.getOracleObject(ScrollableResultSet.java:398)

  at oracle.jdbc.driver.ScrollableResultSet.getString(ScrollableResultSet.java:406)

  at org.apache.jsp.main$jsp._jspService(main$jsp.java:167)

  at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)

  at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

  at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:202)

  at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)

  at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)

  at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)

  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)

  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)

  at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)

  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)

  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)

  at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)

  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)

  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

  at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2344)

  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)

  at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)

  at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)

  at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)

  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)

  at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)

  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)

  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)

  at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)

  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)

  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)

  at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1011)

  at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1106)

  at java.lang.Thread.run(Thread.java:484)
可以看出,rs.getString前面6次循环成功执行,到第七次就突然抛出了异常!
和数据库中的数据没有任何关系,因为我把一次取的字段数降为6个时,就在
while(rs.next())处抛出异常!这就是说,这个rs只能用6次!这是什么鬼错误啊!我都要发疯了!

2.Re:我都要发疯了,为什么ResultSet在使用第7次时会突然抛出异常! [Re: siberia] Copy to clipboard
Posted by: zgd
Posted on: 2004-10-07 23:05

列越界了

3.Re:我都要发疯了,为什么ResultSet在使用第7次时会突然抛出异常! [Re: siberia] Copy to clipboard
Posted by: siberia
Posted on: 2004-10-07 23:10

和列没关系八?

4.Re:我都要发疯了,为什么ResultSet在使用第7次时会突然抛出异常! [Re: siberia] Copy to clipboard
Posted by: dorrenchen
Posted on: 2004-10-08 00:15

show your sql

5.Re:我都要发疯了,为什么ResultSet在使用第7次时会突然抛出异常! [Re: siberia] Copy to clipboard
Posted by: jerry_yuan
Posted on: 2004-10-08 10:27

下标越界

6.Re:我都要发疯了,为什么ResultSet在使用第7次时会突然抛出异常! [Re: siberia] Copy to clipboard
Posted by: dennisjl
Posted on: 2004-10-09 11:43

解决办法如下:

while(rs.hasNext())
{
rs.next();
......
}

不要在循环条件中使用: rs.next().
这样程序在越界时会抛出错误, 而没有处理


   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