使用 JDBC for Oracle 迭代一个 ResultSet 需要很多时间大约 16s? [英] Iterating a ResultSet using the JDBC for Oracle takes a lot of time about 16s?

查看:13
本文介绍了使用 JDBC for Oracle 迭代一个 ResultSet 需要很多时间大约 16s?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

while( result_set.next() )
{
  ...
}

我使用了 System.nanoTime() 并计算了时间,每次迭代所用的时间以毫秒为单位,但整个循环大约需要 16 秒.我正在考虑条件测试花费大量时间的一个可能原因,即 next() 函数.

I have use System.nanoTime() and calculated the time, for each iteration the time taken is in milliseconds but the overall loop takes about 16s. I am considering a possible reason that the condition test is taking a lot of time, the next() function.

仅供参考,我正在连接到远程数据库服务器,并且使用上述方法再次计算出我所做的选择查询以毫秒为单位完成.关于为什么会发生这种情况以及我如何将迭代结果集的时间缩短到最多一秒的任何原因?

FYI I am connecting to a remote database server and the select query that I make is completed in milliseconds again calculated using the above mentioned method. Any reasons about why it's happening and how I can bring the time to iterate the resultset down to at max a second?

我正在处理大约 4000 条记录,每条记录包含大约 10 列,每列的大小约为 10 个字符

I am dealing with about 4000 records and each record contians about 10 columns each having a size of about 10 chars

EDIT2感谢 setFetchsize() 发挥了神奇的作用,真棒,真棒

EDIT2 Thanks setFetchsize() did the magic, awesome, awesome

推荐答案

尝试更改 ResultSet 提取大小.默认情况下,Oracle JDBC 驱动程序一次仅从数据库游标接收 10 行结果集.它可能不会显着提高性能,但没有许多其他选项可以让驱动程序更快地工作.

Try to change ResultSet fetch size. By default, Oracle JDBC driver receives the result set only 10 rows at a time from the database cursor. It may not significantly improve performance but there arent many other options to make driver work faster.

这篇关于使用 JDBC for Oracle 迭代一个 ResultSet 需要很多时间大约 16s?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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