I have a oracle stored proc that needs to be called from my Java program. I had used CallableStatement to pass parameters to the stored proc. I am using oracle thin driver (configured in web logic server against the relevant jndi entry).This stored proc does not have any OUT values. This stored proc accepts a numeric value and does a lot of updates in the db based on the value received.
I get a connection object and then call this stored proc in loop (20 times for passing 20 numbers). When I directly call this stored proc from an oracle client , the execution gets completed in 2-3 seconds. However the behaviour is not predictable from my java code. Some of the calls take even 30-40 seconds to get completed.
I tried to use PreparedStatement instead of CallableStatement and could see marginal performance improvement (though the behaviour is still inconsistent).
- Is it OK in my case to use
PreparedStatementinstead ofCallableStatementgiven that the storedproc does not have any OUT parameters? - Is there any reason why
PreparedStatementhas some performance gain overCallableStatementor is it something that I might have observed incorrectly? - Is there a better approach for solving this performance issue?
From your comment, you have prepareCall inside your loop. An advantage of prepared statements (and callable statements) is that you can prepare it once, and then swap out the values passed in the parameters; there is overhead each time the call is prepared, so if you could bring that outside of your loop, you may find that run time decreases. You may find that turning off AutoCommit also helps, as there is overhead with each commit.
(
conn.setAutoCommit(true)does commit, but I find it clearer to be explicit).