File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes system.exit(0) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "system.exit(0)" Watch "system.exit(0)" New topic
Author

system.exit(0)

Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
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

Joined: Sep 04, 2001
Posts: 34
i would do con.close() first
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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.


GenRocket - Experts at Building Test Data
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
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.


Rob
SCJP 1.4
Jennifer Sohl
Ranch Hand

Joined: Feb 28, 2001
Posts: 455
Thanks guys!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: system.exit(0)