help:对ResultSet进行操作时出现java.lang.NullPointerException错误?

flyboat 2004-10-12 03:10:31
代码:
Connection conn=null;
Statement stm=null;
GetDatabaseConnection getConn=new GetDatabaseConnection("tabxx");
conn=getConn.getConnection();

//查询现有服务类型
String sqlServiceType="select distinct ServiceType from aaa"+
" where UserState=1 or UserState=0";
//查询地区代码
String sqlAreacode="select distinct areacode from aaa"+
" where UserState=1 or UserState=0";
stm=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rsServiceType = stm.executeQuery(sqlServiceType);
ResultSet rsAreacode = stm.executeQuery(sqlAreacode);

//服务的数目
rsServiceType.last();
int serviceNum=rsServiceType.getRow();
rsServiceType.beforeFirst();//

用jsp调用时出错:
500 Servlet Exception
java.lang.NullPointerException
at oracle.jdbc.driver.ScrollableResultSet.cacheRowAt(ScrollableResultSet.java:2086)
at oracle.jdbc.driver.ScrollableResultSet.isValidRow(ScrollableResultSet.java:2060)
at oracle.jdbc.driver.ScrollableResultSet.isEmptyResultSet(ScrollableResultSet.java:2027)
at oracle.jdbc.driver.ScrollableResultSet.last(ScrollableResultSet.java:504)
at testChart.createDataBean.getTotalData(createDataBean.java:57)
at _jsp._boat._indexofchartdemo__jsp._jspService(/boat/IndexOfChartDemo.jsp:21)
at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
at com.caucho.jsp.Page.pageservice(Page.java:571)
at com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:155)
at com.caucho.server.cache.CacheFilterChain.doFilter(CacheFilterChain.java:211)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:177)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:221)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:263)
at com.caucho.server.port.TcpConnection.run(TcpConnection.java:323)
at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:430)
at com.caucho.util.ThreadPool.run(ThreadPool.java:377)
at java.lang.Thread.run(Thread.java:534)


--------------------------------------------------------------------------------
Resin-3.0.7 (built Wed, 24 Mar 2004 04:28:45 PST)
我测试了,数据库已经连上了
哪位大虾帮帮忙?thanks!!!
...全文
333 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
Tasia 2004-10-12
  • 打赏
  • 举报
回复
rsServiceType.getInt(1);?还是rsServiceType.getInt(0);?

下标从1开始计算的。
flyboat 2004-10-12
  • 打赏
  • 举报
回复
别笑话小弟了
:(
给分先!
Arqui 2004-10-12
  • 打赏
  • 举报
回复
java.lang.OutOfMemoryError
这个错误我没有见过 还有益出,真厉害。搬个板凳看
flyboat 2004-10-12
  • 打赏
  • 举报
回复
rsServiceType.getInt(1);?还是rsServiceType.getInt(0);?
flyboat 2004-10-12
  • 打赏
  • 举报
回复
:(
我是做过图形式的统计报表
大虾有什么好的建议吗?
Tasia 2004-10-12
  • 打赏
  • 举报
回复
500 Servlet Exception
java.lang.OutOfMemoryError
呵呵,你占用的内存太多了。内存溢出错误
Tasia 2004-10-12
  • 打赏
  • 举报
回复
ResultSet rsServiceType = stm.executeQuery(sqlServiceType);
int type = 0;
try{
if(rsServiceType.next())
type = rsServiceType.getInt(1);
}catch(...){}

ResultSet rsAreacode = stm.executeQuery(sqlAreacode);
flyboat 2004-10-12
  • 打赏
  • 举报
回复
加了几个stm后出现了下面错误:
500 Servlet Exception
java.lang.OutOfMemoryError
--------------------------------------------------------------------------------
Resin-3.0.7 (built Wed, 24 Mar 2004 04:28:45 PST)

我是用一个jsp调用两个javabean,用来从数据库取得统计数据,然后生成一个jpg图片存在d盘,然后再在页面上显示出来
为什么出现上面问题啊?
多谢了!
Tasia 2004-10-12
  • 打赏
  • 举报
回复
你说的是一种解决方法。
当然还可以把第一次查询的结果保存起来,再查第二次,就没问题。
就像你上面的例子:
ResultSet rsServiceType = stm.executeQuery(sqlServiceType);
int type = 0;
try{
type = rsServiceType.getInt(1);
}catch(...){}

ResultSet rsAreacode = stm.executeQuery(sqlAreacode);
...
flyboat 2004-10-12
  • 打赏
  • 举报
回复

那我在同一个程序中有多个resultset,那得定义好多个stm,有别的方法吗?
Tasia 2004-10-12
  • 打赏
  • 举报
回复
用Oracle数据库?
Oracle数据库中,每个statment只能有一个ResultSet。
你执行这两句的时候:
ResultSet rsServiceType = stm.executeQuery(sqlServiceType);
ResultSet rsAreacode = stm.executeQuery(sqlAreacode);
rsServiceType 的结果在第二句执行完后变为null;

81,114

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧