You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Stephen Westbom <sw...@yahoo.com> on 2003/11/07 15:42:19 UTC

Re: R�f. : Re: R�f. : Re: R�f. : RE: dbcp size nightmare

You are forever banished to the ranks of the novice Java programmers :)

--- Martin van den Bemt <ml...@mvdb.net> wrote:
> My bad wasn't thinking.. 
> 
> Mvgr,
> Martin
> 
> On Fri, 2003-11-07 at 15:12, pgarvie wrote:
> > A finally block is ALWAYS executed, assuming you don't call System.exit(0) 
> > or pull the plug while you're in the catch.
> > 
> > 
> > 
> > 
> > 
> > 
> > At 07:55 AM 11/7/2003, you wrote:
> > >Your finally block is not executed in case of an exception, since you
> > >are throwing an exception fro the catch :)
> > >
> > >Mvgr,
> > >Martin
> > >
> > >On Fri, 2003-11-07 at 09:53, meissa.Sakho@assetmanagement.natexis.fr
> > >wrote:
> > > > the fragment code below describe how I acquire and close ressource.
> > > >
> > > > protected void executeDB() throws TechnicalException
> > > >         {
> > > >                 Connection connection = null;
> > > >                 Statement statement = null;
> > > >
> > > >                 connection = getConnection();
> > > >
> > > >                 try
> > > >                 {
> > > >                         statement = connection.createStatement();
> > > >                         executeTransaction(statement);
> > > >
> > > >                 }
> > > >                 catch (SQLException e1)
> > > >                 {
> > > >                         throw new TechnicalException(this, "Probleme 
> > > d'acc�s � la base de donn�e impossible de cr�er un objet
> > > > Statement " + e1.getMessage());
> > > >
> > > >                 }
> > > >
> > > >                 finally
> > > >                 {
> > > >                         // on libere les ressources
> > > >                         release(connection, statement);
> > > >                         sqlQueries = new ArrayList();
> > > >                 }
> > > >
> > > >         }
> > > >
> > > >
> > > > the getConnection() method will acquire a connection defined in
> server.xml
> > > > file
> > > > while the release connection will close ressources.
> > > >
> > > > Meissa Sakho
> > > > NATEXIS ASSET MANAGEMENT
> > > > Direction de l'organisation
> > > > Tel. : 01 58 19 45 71
> > > > http://www.assetmanagement.natexis.fr
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Kwok Peng Tuck <pe...@makmal.net>
> > > > 07/11/2003 09:08
> > > > Veuillez r�pondre � "Jakarta Commons Users List"
> > > >
> > > >
> > > >         Pour :  Jakarta Commons Users List 
> > > <co...@jakarta.apache.org>
> > > >         cc :
> > > >         Objet : Re: R�f. : Re: R�f. : RE: dbcp size nightmare
> > > >
> > > >
> > > > Uh, sorry, I didn't quite get that. Could you include your code for us
> > > > to see ?
> > > >
> > > >
> > > > meissa.Sakho@assetmanagement.natexis.fr wrote:
> > > >
> > > > >better,
> > > > >Im closing in my finally statement all resources.
> > > > >
> > > > >Resultset,statement and connection.
> > > > >
> > > > >Meissa Sakho
> > > > >NATEXIS ASSET MANAGEMENT
> > > > >Direction de l'organisation
> > > > >Tel. : 01 58 19 45 71
> > > > >http://www.assetmanagement.natexis.fr
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >Kwok Peng Tuck <pe...@makmal.net>
> > > > >07/11/2003 08:22
> > > > >Veuillez r�pondre � "Jakarta Commons Users List"
> > > > >
> > > > >
> > > > >
> > > > >        Pour :  Jakarta Commons Users List
> > > > <co...@jakarta.apache.org>
> > > > >        cc :
> > > > >
> > > > >        Objet : Re: R�f. : RE: dbcp size nightmare
> > > > >
> > > > >
> > > > >Make sure that you include a finally block after your catch, in which
> > > > >
> > > > >you actually close the connection.
> > > > >
> > > > >try {
> > > > >    //Do your db con here.
> > > > >
> > > > >}catch (SQLException e) {
> > > > >    e.printStackTrace() ;
> > > > >}finally {
> > > > >     try {
> > > > >          if(con!=null) { con.close() ;  }
> > > > >    }catch (SQLException e) {
> > > > >       e.printStackTrace() ;
> > > > >    }
> > > > >}
> > > > >
> > > > >You can find this design pattern in the tomcat doc as well (under JNDI
> > > > >
> > > > >datasource how-to)  .
> > > > >
> > > > >
> > > > >meissa.Sakho@assetmanagement.natexis.fr wrote:
> > > > >
> > > > >
> > > > >
> > > > >>I do close everything.
> > > > >>I'm wondering if it's not because I don't specify a factory
> > > > >>in the pool config.
> > > > >>
> > > > >>any other suggestion ...
> > > > >>
> > > > >>
> > > > >>
> > > > >>Meissa Sakho
> > > > >>NATEXIS ASSET MANAGEMENT
> > > > >>Direction de l'organisation
> > > > >>Tel. : 01 58 19 45 71
> > > > >>http://www.assetmanagement.natexis.fr
> > > > >>
> > > > >>
> > > > >>
> > > > >>
> > > > >>
> > > > >>"Michael Holly" <MH...@talisentech.com>
> > > > >>06/11/2003 17:31
> > > > >>Veuillez r�pondre � "Jakarta Commons Users List"
> > > > >>
> > > > >>
> > > > >>
> > > > >>       Pour :  "'Jakarta Commons Users List'"
> > > > >>
> > > > >>
> > > > >
> > > > ><co...@jakarta.apache..org>
> > > > >
> > > > >
> > > > >>       cc :
> > > > >>
> > > > >>       Objet : RE: dbcp size nightmare
> > > > >>
> > > > >>
> > > > >>Make sure you are closing all your resources after running the SQL.
> > > > >>Connection, Statement, ResultSet.
> > > > >>
> > > > >>
> > > > >>Michael Holly
> > > > >>
> > > > >>"Developing Software from requirements and Walking on water, both are
> > > > >>easy when frozen."
> > > > >>"Good, Fast, and Cheap... pick Two"
> > > > >>
> > > > >>
> > > > >>
> > > > >>-----Original Message-----
> > > > >>From: meissa.Sakho@assetmanagement.natexis.fr
> > > > >>[mailto:meissa.Sakho@assetmanagement.natexis.fr]
> > > > >>
> > > > >>Sent: Thursday, November 06, 2003 7:11 AM
> > > > >>To: commons-user@jakarta.apache.org
> > > > >>Subject: dbcp size nightmare
> > > > >>
> > > > >>
> > > > >>
> > > > >>hi all,
> 
=== message truncated ===


__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree

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


RE: dbcp

Posted by Vic Cekvenich <ce...@baseBeans.com>.
Using connection pooling in this way is not best practice.

Consider this instead:
http://marc.theaimsgroup.com/?l=struts-user&m=106780084619434&w=2
That is using a DAO, like example of PetStore 3 on iBatis.com

-- 
Victor Cekvenich,
Struts Instructor
(215) 321-9146

Advanced Struts Training
<http://basebeans.com/do/cmsPg?content=TRAINING> Server Side Java
training with Rich UI, mentoring, designs, samples and project recovery
in North East.
Simple best practice basic Portal, a Struts CMS, Membership, Forums,
Shopping and Credit processing, <http://basicportal.com> software, ready
to develop/customize; requires a db to run.



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


Re: Réf. : Re: Réf. : Re: Réf. : RE: dbcp size nightmare

Posted by Martin van den Bemt <ml...@mvdb.net>.
ehmm you mean even though if I am a an expert java programmer I still
can learn :) 
I tested what you said of course (don't actually have any code with
finally and returning / throwing new exceptions in a catch) and you are
right :)
So my wasn't thinking was actually lack of knowledge :)

Mvgr,
Martin

On Fri, 2003-11-07 at 15:42, Stephen Westbom wrote:
> You are forever banished to the ranks of the novice Java programmers :)
> 
> --- Martin van den Bemt <ml...@mvdb.net> wrote:
> > My bad wasn't thinking.. 
> > 
> > Mvgr,
> > Martin



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