Originally posted by Paul Sturrock:
Quite the opposite. Yes using a statement cache in the DB layer will possibly use more memory than not using one, but it will reduce the work needed to run a query. Remember that SQL has to be interpreted each time a query is done if you just use Statements, where as Prepared Statements are interpreted and compiled only once.
Originally posted by Ivan Jouikov:
Can somebody verify this? As far as I remember, JDBC ENCOURAGES to use PreparedStatement over normal statements...
[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Originally posted by Paul Sturrock:
the only clean up statement you need in your finally block is to close the connection. All JDBC resources hang off this - so close the connection and your statement is also closed.
[ July 12, 2004: Message edited by: Paul Sturrock ]
The future is here. It's just not evenly distributed yet. - William Gibson
Sonny Gill LinkedIn
Tweets
with some JDBC drivers, not closing the resultset and statement explicitly may leave some unreleased database resources even when you close the connection
Also, if the connection was taken from a pool, calling close on it might simply return it back to the pool without actually closing it or the ResultSets and Statements
Originally posted by Bear Bibeault:
I almost always use PreparedStatements. I can think of no valid reason not to use them over "normal" statements; especially when any run-time parameters are used.
Anecdotal evidence of performance differences aside, I'd advise using what makes the most sense (which in most cases is a PreparedStatement) to your application, and then worry about any performance issues if any such issues pop up.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
We really don't need to wait until performance becomes an issue in our application, in fact we should avoid this before we get there. That is Defensive Programming.
Originally posted by Paul Sturrock:
with some JDBC drivers, not closing the resultset and statement explicitly may leave some unreleased database resources even when you close the connection
This doesn't sound correct. The Statement and ResultSet both use the Connection instance to communicate with the DB. No Connection == no route to the DB. Specifically which drivers have you heard this about?
The future is here. It's just not evenly distributed yet. - William Gibson
Sonny Gill LinkedIn
Tweets
Originally posted by Sonny Gill:
Well I read it a while ago, but I cant find any references to where I read it now. As far as I can remember, it was some Oracle JDBC driver, and it was suggested that not closing the Statement explicitly might leave some cursors open in the database server. Most likely, if true, this was a problem in the early drivers, and was fixed.
You have to be odd to be #1 - Seuss. An odd little ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|