oracle 如何为 jdbc odbc 驱动程序设置获取大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1478177/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to set fetch size for jdbc odbc driver
提问by Fell
Im using sun.jdbc.odbc.JdbcOdbcDriver to connect to an oracle database.I know I would be probably be better off using the thin driver but I want the app to work without specifying the db server name and port no.My connection string is like jdbc:odbc:DSN.
我使用 sun.jdbc.odbc.JdbcOdbcDriver 连接到 oracle 数据库。我知道我可能最好使用瘦驱动程序,但我希望应用程序在不指定数据库服务器名称和端口号的情况下工作。我的连接字符串是像 jdbc:odbc:DSN。
The queries that I execute in my application may return millons of rows.All the data is critical so I cannot limit them within the query.My concern is for my java app running into memory issues.
我在我的应用程序中执行的查询可能会返回数百万行。所有数据都很关键,所以我不能在查询中限制它们。我担心的是我的 java 应用程序遇到内存问题。
When I check the fetch size of the statement it is set to 1.This seems extremely sub-optimal(A query retrieving 45K rows took abt 13 mins)to me and I would like to have a fetch size of atleast 500 so as to improve performance.
当我检查语句的提取大小时,它被设置为 1。这对我来说似乎非常次优(检索 45K 行的查询花了大约 13 分钟),我希望获取大小至少为 500 以便改进表现。
My understanding is that when my query is executed(I'm using Statement) the statement object points to the results on the database which I iterate using a ResultSet. The resultSet will hit the database to fetch n no of rows (where n is fetch size) each time I do a resultSet.next(). Is this interpretation correct? If so does it mean that my app will neverface any out of memory issues until my fetch size is so large that the JVM gets swamped?
我的理解是,当我的查询被执行时(我正在使用 Statement),语句对象指向我使用 ResultSet 迭代的数据库上的结果。每次我执行 resultSet.next() 时,resultSet 都会访问数据库以获取 n 行(其中 n 是获取大小)。这个解释正确吗?如果是这样,这是否意味着我的应用程序永远不会面临任何内存不足问题,直到我的提取大小太大以至于 JVM 被淹没?
When I do a stmt.setFetchSize() after creating a statement I get an invalid fetch size sql exception.I am able to avoid this exception if I set the stmt.setMaxRows() to a larger value than the fetch size.But
1. I dont want my results to be limited to the MaxRows value.
2. Tried setting max rows to a huge value and tried with fetch size of 500 but saw no improvement in time taken.
当我在创建语句后执行 stmt.setFetchSize() 时,我得到一个无效的 fetch size sql 异常。如果我将 stmt.setMaxRows() 设置为比获取大小更大的值,我可以避免这个异常
。但是1。我不希望我的结果仅限于 MaxRows 值。
2. 尝试将 max rows 设置为一个巨大的值,并尝试将 fetch size 设为 500,但没有看到所花费的时间有所改善。
Please help me figure out how I can set a valid fetch size and get some improvement.Any other optimization suggestions for the same driver would be appreciated.
请帮助我弄清楚如何设置有效的提取大小并获得一些改进。对于同一驱动程序的任何其他优化建议将不胜感激。
Thanks,
Fell
谢谢,
落
回答by Justin Cave
I haven't used a JDBC-ODBC bridge in quite a few years, but I would expect that the ODBC driver's fetch size would be controlling. What ODBC driver are you using and what version of the ODBC driver are you using? What is the fetch size specified in the DSN?
我已经有好几年没有使用 JDBC-ODBC 桥接器了,但我希望 ODBC 驱动程序的获取大小会受到控制。您使用的是什么 ODBC 驱动程序以及您使用的是什么版本的 ODBC 驱动程序?DSN 中指定的提取大小是多少?
As a separate issue, I would seriously question your decision to use a JDBC-ODBC bridge in this day and age. A JDBC driver can use a TNS alias rather than explicitly specifying a host and port which is no harder to configure than an ODBC DSN. And getting rid of the requirement to install, configure, and maintain an ODBC driver and DSN vastly improves performance an maintainability.
作为一个单独的问题,我会严重质疑您在当今时代使用 JDBC-ODBC 桥的决定。JDBC 驱动程序可以使用 TNS 别名,而不是显式指定主机和端口,这并不比 ODBC DSN 更难配置。摆脱安装、配置和维护 ODBC 驱动程序和 DSN 的要求极大地提高了性能和可维护性。
回答by ZZ Coder
Are you sure the fetch size makes any difference in Sun's ODBC-JDBC driver? We tried it a few years ago with Java 5. The value is set, even validated but never used. I suspect it's still the case.
您确定获取大小对 Sun 的 ODBC-JDBC 驱动程序有任何影响吗?几年前,我们在 Java 5 中尝试过。该值已设置,甚至经过验证但从未使用过。我怀疑情况仍然如此。
回答by sal
Use JDBC. There is no advantage in using ODBC bridge. In PreparedStatement or CallableStatement you can call setFetchSize() to restrict the rowset size.
使用 JDBC。使用 ODBC 桥没有优势。在 PreparedStatement 或 CallableStatement 中,您可以调用 setFetchSize() 来限制行集大小。