Should I explicitly disconnect from the database when using Java?

Is it necessary to disconnect from the database after completing a job in Java? If it is not disabled, will this lead to a memory leak?

+3
source share
5 answers

You should provide more detailed information about which structure you are using or something like that.

Anyway, are you using JDBC? If so, you should close the following objects using their respective methods close(): Statement, ResultSet, and Connection.

+4
source

You should always close all your connections, messages and ResultSets.

, , , .

+6

, JDBC, . , JDBC , , ( ). JDBC- , , .

(, JBoss) , , , , .

, JDBC java-, .

+3

I have no source, but I believe (if I remember correctly, it has been a while since I touched JDBC), it depends on the implementation of the JDBC driver. You should always close your connections and clean up after yourself, as not all JDBC drivers do this for you (although some may).

This goes back to the rule that I like - if I create or open something, I am responsible for deleting or closing it.

+1
source

yes and yes

-2
source

Source: https://habr.com/ru/post/1720592/


All Articles