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 DBCP - Why we close connection
Date Thu, 15 Jun 2006 15:00:59 GMT
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

 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message