commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jawed Nazar Ali" <ja...@spectrum-tech.com>
Subject RE: DBCP - Why we close connection
Date Fri, 16 Jun 2006 06:26:33 GMT
Got the point, thanks a lot guys.

Jawed

-----Original Message-----
From: Kenneth Huang [mailto:yourenzhuce@gmail.com] 
Sent: Friday, June 16, 2006 8:08 AM
To: Jakarta Commons Users List
Subject: Re: DBCP - Why we close connection

Hi, Jawed:

I think you just want to know why it close conn in the end. 

(1) If you use DB connection pool(DBCP) to visit DB, conn.close() will put
this instance to pool and can be used next time.
(2) If you don't use DBCP in your app, conn.close() will release the
resource used by this instance, esp. a socket connection, or a file
resource.

------------------				 
Kenneth Huang
2006-06-16

-------------------------------------------------------------
-----Original Message-----
From:Jawed Nazar Ali
Sent: 2006-06-15 23:00:06
To:commons-user@jakarta.apache.org
Subject:DBCP - Why we close connection


Hello,


        try {
            conn =
DriverManager.getConnection("jdbc:apache:commons:dbcp:example");
            stmt = conn.createStatement();
            rset = stmt.executeQuery(args[1]);
            int numcols = rset.getMetaData().getColumnCount();
            while(rset.next()) {
                for(int i=1;i<=numcols;i++) {
                    System.out.print("\t" + rset.getString(i));
                }
                System.out.println("");
            }
        } catch(SQLException e) {
            e.printStackTrace();
        } finally {
            try { rset.close(); } catch(Exception e) { }
            try { stmt.close(); } catch(Exception e) { }
            try { conn.close(); } catch(Exception e) { }
        }

 

Why we close conn at the end, I don't understand this. Any explanation?


Regards,

Jawed Nazar Ali

 





---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message