从 sqldeveloper 运行 sql 脚本与从 java 代码运行 sql 脚本
我正在尝试在 Oracle 11g R2 中运行一些 sql 脚本
当我尝试从独立的 java 代码运行这些脚本时,查询运行了 40 多分钟,但是当我从 sqldeveloper 客户端运行相同的脚本时,它在 4 分钟内运行
可能是什么原因是什么?
编辑
好吧,我正在做一些更新脚本,调用 pl/sql 过程
是的,我正在做字符串连接
I am trying to run a few sql scripts in Oracle 11g R2
When I try to run these scripts from a standalone java code the query runs into 40 odd minutes but when I run the same from the sqldeveloper client it runs in 4 minutes
What could be the reason ?
EDIT
Well I am doing a few update scripts, calling a pl/sql procedure
Yes I am doing a string concatenation
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要从 java 执行 sql,请执行以下步骤:
计时示例来自我的环境中的一个简单语句。您的环境会有所不同,但时间比例会相似。关键是打开连接的成本可能比实际执行语句的成本要高得多。
检查您的代码是否未打开连接并在循环内准备语句。这可能会占用您很大一部分时间,并解释了为什么脚本比使用 sql Developer 启动时要慢。您应该打开连接一次,然后重新使用该连接。如果您没有上传大量数据,那么无论代码是从 sql Developer 还是其他客户端启动,代码在数据库服务器上运行所需的时间都是相同的。
To execute the sql from java, you perform the following steps:
Timing examples are from my environment for a simple statement. Your environment will be different, but the proportional amount of time will be similar. The point is that opening the connection can be far more expensive than actually executing the statement.
Check that your code is not opening a connection and preparing a statement inside of a loop. That could account for a big proportion of your time and explain why the script is slower then when launched with sql developer. You should open the connection once and then re-use the connection. If you are not uploading a large amount of data, then the amount of time the code takes to run on the database server is the same whether it was initiated from sql developer or some other client.