Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 51477 invoked from network); 9 Apr 2005 09:15:56 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 9 Apr 2005 09:15:56 -0000 Received: (qmail 441 invoked by uid 500); 9 Apr 2005 09:15:52 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 427 invoked by uid 500); 9 Apr 2005 09:15:52 -0000 Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Users List" Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 410 invoked by uid 99); 9 Apr 2005 09:15:52 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from euros.telenet-ops.be (HELO euros.telenet-ops.be) (195.130.132.55) by apache.org (qpsmtpd/0.28) with ESMTP; Sat, 09 Apr 2005 02:15:50 -0700 Received: from apate.telenet-ops.be (apate.telenet-ops.be [195.130.132.57]) by euros.telenet-ops.be (Postfix) with ESMTP id 0E2CD4B6E8 for ; Sat, 9 Apr 2005 11:10:56 +0200 (MEST) Received: from localhost (localhost.localdomain [127.0.0.1]) by apate.telenet-ops.be (Postfix) with SMTP id 08D2A38136 for ; Sat, 9 Apr 2005 11:10:46 +0200 (CEST) Received: from [127.0.0.1] (dD5E05EF3.access.telenet.be [213.224.94.243]) by apate.telenet-ops.be (Postfix) with ESMTP id D502D3808A for ; Sat, 9 Apr 2005 11:10:45 +0200 (CEST) Message-ID: <42579C0C.6010309@pandora.be> Date: Sat, 09 Apr 2005 11:10:36 +0200 From: Dirk Verbeeck User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.3) Gecko/20040910 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Jakarta Commons Users List Subject: Re: help on DBCP References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N It is indeed a trivial problem. The close() methods aren't called inside your inner for loop. So for each 3 connections created in the "for j" loop only 1 is closed. The order of closing rset,stmt,conn is correct. -- Dirk Arjen van der Weijden wrote: > Hi folks, > > Just started out examining DBCP, so I'm completely new to the subject. > I adapted the example given by Dirk V. (given below). I put some stuff in a > for loop. > > The PROBLEM is that after a few loops the program seems to hang (less than > 10 connections). > > Can anybody help me on this, it must be someting trivial I guess? > > Configuration standard mysql installation on a redhat > _____________________________________________________________________________________________ > public class DataSourceExample { > > public static void main(String[] args) { > try { > Class.forName("com.mysql.jdbc.Driver").newInstance(); > } > catch (Exception ex) { > ex.printStackTrace(); > } > > DataSource dataSource = > setupDataSource("jdbc:mysql://localhost/mysql?user=mysql&password=pizza"); > > Connection conn = null; > Statement stmt = null; > ResultSet rset = null; > > for (int ii = 0; ii < 3; ii++) { > try { > for (int j = 0; j < 3; j++) { > conn = dataSource.getConnection(); > stmt = conn.createStatement(); > String $query = "SELECT * FROM user"; > rset = stmt.executeQuery($query); > System.out.println("Results:"); > 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) { } > } > } > } > > public static DataSource setupDataSource(String connectURI) { > ConnectionFactory connectionFactory = new > DriverManagerConnectionFactory(connectURI,null); > PoolableConnectionFactory poolableConnectionFactory = new \ > > PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true); > PoolingDataSource dataSource = new > PoolingDataSource(connectionPool); > return dataSource; > } > } --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org