aspose file tools*
The moose likes JDBC and the fly likes Just closing connection enough? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Just closing connection enough?" Watch "Just closing connection enough?" New topic
Author

Just closing connection enough?

Mukul Kapur
Greenhorn

Joined: Jun 21, 2009
Posts: 1
Hi friends..This is my first post...I am a newbie Java Developer..Okay Here goes
I have just made a LAN based Java application using Swing,JDBC with backend as MS-Access..The backend is on a shared network drive..
The application is distributed as jar files on the LAN PCs..
Everywhere I have connected to the database I have just closed the connection explicitly like this
con.close();
I do not close the associated resultset and statement explicitly

The specification says associated statements and resultsets close when you close
the connection,even if you don't explicitly close them
Also I am not using connection pool..its simple basic connection using DriverManager

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbcdbcSN name";
String user = "";
String pw = "";
con = DriverManager.getConnection(url, user, pw);
Statement stmt = con.createStatement();
String select = "" ;
ResultSet rows = stmt.executeQuery(select);

Till now no performance problems..over 4K records have been added..
JVM is not exiting or anything..
On the net everyone says to explicitly close everything..but I did not know that
earlier..

My question is
Is closing just the connection enough..?
Is there any way I can check whether statements and resultsets have been implicitly closed?
Later on will it cause any performance problems or anything...?
Shud I change my code and add rs.close() and stmt.close() everywhere..?

If specification says everything closes on
closing connection why do ppl insist on closing everything explicitly..?
Or is this driver dependent..don't the drivers go through the specification..
My driver is the Sun JDBC ODBC bridge.....

There would be 8-10 users maximum at a time using the application concurrently...

Any help would be appreciated..Thanks in advance..
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Mukul Kapur wrote:
My question is
Is closing just the connection enough..?

Yes, provided you closed it in "finally" block.
Mukul Kapur wrote:
Is there any way I can check whether statements and resultsets have been implicitly closed?
Later on will it cause any performance problems or anything...?
Shud I change my code and add rs.close() and stmt.close() everywhere..?

Once you closed the connection , the associated result set and statements also gets closed.
Mukul Kapur wrote:
If specification says everything closes on
closing connection why do ppl insist on closing everything explicitly..?

Because its good programming practice. Many times you need to kept a connection live for the next query, at such situation you can close out all the rs and statement dealt with the previous query/transaction.

And Welcome to JR and UseRealWords

[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31079
    
163

Mukul Kapur wrote:If specification says everything closes on closing connection why do ppl insist on closing everything explicitly..?

Because we've gotten burned by a driver that doesn't work as advertised.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Just closing connection enough?