I have a website which is getting a massive number of hits. I'm experienced problems, including JDBC connection errors.
I'm a bit confused about closing PreparedStatement
. Do I need to close PreparedStatement
or is it just enough to only close Statement
?
Also, what about ResultSet
? Do I need to close it too?
Resultset, preparedstatement, statement all are created from connection. If you have closed the connection, automatically all above will be closed as parent is not available.
JDBC Statement objects must always be closed by the application instead of allowing them to be closed by garbage collection.
You should explicitly close Statements , ResultSets , and Connections when you no longer need them, unless you declare them in a try -with-resources statement (available in JDK 7 and after). Connections to Derby are resources external to an application, and the garbage collector will not close them automatically.
(2) Closing the statement object does not close the resultset object.
Yes, you have to close the prepared statements (PreparedStatement
Object) and result sets as they may cause memory leakage.
For more information, see Using Prepared Statements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With