Forums Register Login

Statement vs. Prepared Statement

+Pie Number of slices to send: Send
I want to know the clear difference between the use of statement and prepared statement. In case of prepared statement, the object is created first time in the memory of database and can be used for all later invocation. If that is true, in all our web application, we should use prepared statement always, since multiple users will be accessing the website and the same object of that prepared statement can be used multiple times. My doubt is that, what is the purpose of having normal statement then? Another confusion, when at the end of method we close the prepared statement, does the object get closed from the memory of the database as well or only gets closed from the server?
Appreciate your detailed input on this.
+Pie Number of slices to send: Send
First of all, you should read this article.
Second, you don't have to worry about any "objects" being "closed" in the database. What the use of PreparedStatement does in the database is basically caching; the database engine compiles the SQL skeleton into a query plan and caches the resulting "executable". It's up to the database server whether it wants to keep the compiled stuff in memory after the statements have been executed and committed.
snakes are really good at eating slugs. And you wouldn't think it, but so are tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 975 times.
Similar Threads
ConnectionPool causing memory leak
ResultSet
resultset
J2EE application giving exeptions in multiuser mode
Garbage Collection of Statement object being unreferenced
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 07:22:33.