java - Do MySQL Connections close automatically when the program exits? -


this question has answer here:

if create mysql connection in java program, , program exits main method, happens mysql connection?

public static void main(string args[]) {     connection conn = getconnection(...);      return;     } 

does connection closed automatically?

or connection stays alive until times out?

no, that's resource leak right there. connection object cease exist because jvm terminates when main() ends, resources allocated on database server stay open while till database decides reclaim them after timeout.

this bad practice because if program terminates without explicitly closing database connection, happens database operations (like insert, updates etc.) done before, undefined. some, jdbc drivers commit changes , implicit rollback.

it highly recommended not depend on such undefined database specific behaviour because you're giving benefits of using database agnostic jdbc api , compromise application's portability no gains in return.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -