This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Just closing connection enough?

 
Mukul Kapur
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2905
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33696
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic