Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

system.exit(0)

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just curious...
What is the standard procedure for closing database connections?
Does system.exit(0) automatically do this?
And if it does, is just calling this method the proper way to shut down a connection, or should I do a con.close() and then a System.exit(0)?
What's the difference?
Thanks in advance!
 
vicky bawge
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i would do con.close() first
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.exit(0) is a method that kills the main() thread in an application. It has nothing to do with your database Connection.
The proper way is to use the close() method in the Connection API. That will close the connection to your Database cleanly.
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As a general rule, any time you use non-java resources you are going to be responsible for disposing of them. That includes all JNI libraries, as well as things like database connections and file descriptors.
If the driver is 100% java, it may be smart enough to dispose of itself correctly when exit the JVM, but I wouldn't count on that behavior.
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic