X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2BC769DC883 for ; Sat, 17 Dec 2005 01:35:09 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 50790-02 for ; Sat, 17 Dec 2005 01:35:07 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from web31802.mail.mud.yahoo.com (web31802.mail.mud.yahoo.com [68.142.207.65]) by postgresql.org (Postfix) with SMTP id 832B49DC880 for ; Sat, 17 Dec 2005 01:35:06 -0400 (AST) Received: (qmail 93584 invoked by uid 60001); 17 Dec 2005 05:35:06 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:Cc:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=DxyPQKT+aaiSlgtS04UKoaYSa7wu3xE23Yyg8BEaBnQ4lzNvjGOShFMAKyTEIhPvlSczmk4Apl1MJyLcD9UxVB3dVgxqR2tiFO0ZufRyHHSXqnghleDJ+gp4ufBz3KuXwFR0TJs7FCHtgpTxe6eYBDjb1QZ76rkPNjGvW37YmIo= ; Message-ID: <20051217053506.93582.qmail@web31802.mail.mud.yahoo.com> Received: from [61.246.49.145] by web31802.mail.mud.yahoo.com via HTTP; Fri, 16 Dec 2005 21:35:06 PST Date: Fri, 16 Dec 2005 21:35:06 -0800 (PST) From: Simon Moses Subject: Re: setting & using connection pool in beans for tomcat. To: Dave Cramer Cc: pgsql-jdbc@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-926868083-1134797706=:93012" Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=2.092 required=5 tests=[DEAR_SOMETHING=1.612, DNS_FROM_RFC_ABUSE=0.479, HTML_MESSAGE=0.001] X-Spam-Score: 2.092 X-Spam-Level: ** X-Archive-Number: 200512/77 X-Sequence-Number: 14408 --0-926868083-1134797706=:93012 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit dear dave, i have set connection pooling in tomcat. with the sample code now i can connect to pool from jsp. the sample code given in that page is not connecting to my database. but same code in jsp is connecting. but i want to write a .java file which should hold the database connection(from tomcat connection pool) code and have a getConnection method. the one i am using now is
 
 package com.moses.srivaru;
 
 import java.sql.*;
 import java.io.*;
 
 public class DBCon{
     private Connection con = null;
 
     public DBCon(){
         try{
             String url = "jdbc:postgresql://localhost:5432/srivaru";
             Class.forName("org.postgresql.Driver");
             con = DriverManager.getConnection(url,"postgres","postgres");
         }catch(Exception e){System.out.println(e);}
     }
 
     public Connection getCon(){
         return con;
     }
 
     public void close(){
         try{
             con.close();
         }catch(Exception e){
             System.out.println(e);
         }
     }
 
 }
 
 
this class is in tomcat_home/common/classes/com/moses/srivaru tell me where i should keep the new class which gives connection from tomcat connection pool. thanks for your reply, Simon Moses. Dave Cramer wrote: Simon, Have you looked at http://jdbc.postgresql.org/documentation/head/tomcat.html Dave On 16-Dec-05, at 5:10 AM, Simon Moses wrote: > dear sir, > > i have set connection pooling in tomcat. now i can use connections > from that pool in jsp. > > but i want all database accessing code in beans not in jsp. how to > do it? > > i want to write a class(CPCon.java) with methods like > { > void ConnectionPoolOpen(){} > Connection getConnection(){} > void closeConnection(){} > .... > } > > and call this class in all jsp pages with useBean tag. > > if i write like this, is the connection pool is going to be used by > all jsp pages for all tomcat server clients? > > if not how to do this? > > i am using tomcat 5.0. j2se1.4 and postgresql 8.0 with > postgresql-8.0-312.jdbc3.jar driver. > > regards, > Simon Moses. > > > > ************************** > Visit My Home Page > http://www.geocities.com/ks_moses > updated: 28 Sep 2004. > Simon Moses > ************************** > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com ---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster ************************** Visit My Home Page http://www.geocities.com/ks_moses updated: 28 Sep 2004. Simon Moses ************************** __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com --0-926868083-1134797706=:93012 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 8bit
dear dave,

i have set connection pooling in tomcat. with the sample code now i can connect to pool from jsp.

the sample code given in that page is not connecting to my database. but same code in jsp is connecting.

but i want to write a .java file which should hold the database connection(from tomcat connection pool) code and have a getConnection method. the one i am using now is

<pre>

package com.moses.srivaru;

import java.sql.*;
import java.io.*;

public class DBCon{
    private Connection con = null;

    public DBCon(){
        try{
            String url = "jdbc:postgresql://localhost:5432/srivaru";
            Class.forName("org.postgresql.Driver");
            con = DriverManager.getConnection(url,"postgres","postgres");
        }catch(Exception e){System.out.println(e);}
    }

    public Connection getCon(){
        return con;
    }

    public void close(){
        try{
            con.close();
        }catch(Exception e){
            System.out.println(e);
        }
    }

}

</pre>

this class is in tomcat_home/common/classes/com/moses/srivaru
tell me where i should keep the new class which gives connection from tomcat connection pool.


thanks for your reply,
Simon Moses.


Dave Cramer <pg@fastcrypt.com> wrote:
Simon,

Have you looked at

http://jdbc.postgresql.org/documentation/head/tomcat.html

Dave
On 16-Dec-05, at 5:10 AM, Simon Moses wrote:

> dear sir,
>
> i have set connection pooling in tomcat. now i can use connections
> from that pool in jsp.
>
> but i want all database accessing code in beans not in jsp. how to
> do it?
>
> i want to write a class(CPCon.java) with methods like
> {
> void ConnectionPoolOpen(){}
> Connection getConnection(){}
> void closeConnection(){}
> ....
> }
>
> and call this class in all jsp pages with useBean tag.
>
> if i write like this, is the connection pool is going to be used by
> all jsp pages for all tomcat server clients?
>< br>> if not how to do this?
>
> i am using tomcat 5.0. j2se1.4 and postgresql 8.0 with
> postgresql-8.0-312.jdbc3.jar driver.
>
> regards,
> Simon Moses.
>
>
>
> **************************
> Visit My Home Page
> http://www.geocities.com/ks_moses
> updated: 28 Sep 2004.
> Simon Moses
> **************************
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com


---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster



**************************
Visit My Home Page
http://www.geocities.com/ks_moses
updated: 28 Sep 2004.
Simon Moses
**************************

__________________________________________________
Do You Yahoo!?
Tired of spam? Y ahoo! Mail has the best spam protection around
http://mail.yahoo.com --0-926868083-1134797706=:93012--