ResultSet - Cursor:rs.next()花费大量时间 [英] ResultSet - Cursor : rs.next() Taking lot of time

查看:107
本文介绍了ResultSet - Cursor:rs.next()花费大量时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从数据库返回的游标在31毫秒(毫秒)内执行。

I have a cursor returned from Database executes in 31ms (milliseconds) .

但是当我使用这个超过1500行的游标来获取行时

But when I use this cursor having more than 1500 rows for fetching rows

  ResultSet rs = (ResultSet)cstm.getObject(6);

  while(rs.next()){
     system.out.println("...");
  }

只需简单地横穿光标的每一行就需要超过40秒(40000) ms)

Just simple transversing through each row of cursor it's taking more than 40 seconds (40000 ms)

可以做些什么?

推荐答案

的确,通过默认JDBC使用的提取大小为10.因此,如果未设置更大的值,则为下一个记录调用数据库正好150次...

Indeed, by default JDBC use a fetch size of 10. Thus, if you don't set to a greater value, you call database for next records exactly 150 times ...

全部你要做的是通过将fetchSize设置为100来测试性能,例如:

All you have to do is to test performance by setting fetchSize to.. 100 for instance :

statement.setFetchSize(100);

您可以根据您的环境使用此号码来提高效果。

You can play with this number to improve performance according to your environnement.

这篇关于ResultSet - Cursor:rs.next()花费大量时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆