#1
  1. No Profile Picture
    Mentat of IX
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Bucuresti / Toronto
    Posts
    112
    Rep Power
    12

    setting up Connection pooling in a tomcat app with postgreSQL


    I'm looking for a practical example of some sort , i guess . So far i checked the JDBC documentation at sun and tried a few things suggested in a J2EE book and none seem to work .

    I basically tried the code example given at sun's jdbc tutorial :
    com.dbaccess.BasicDataSource ds =
    new com.dbaccess.BasicDataSource();

    i my case i guess
    org.postgresql.BasicDataSource ds = new org.postgresql.BasicDataSource() however that class cannot be found while the closest one from that package
    org.postgresql.jdbc2.optional.BaseDataSource seems to be abstract .

    I also tried the example from a J2EE book :
    Code:
    InitialContext ctx = new InitialContext( );
    
    DataSource ds = (DataSource) ctx.lookup("jdbc/database");
    
    con = ds.getConnection( );
    also added this to server.xml for tomcat
    Code:
    <Resource name="jdbc/database" auth="container"
                     type="javax.sql.DataSource">
           </Resource>
             <ResourceParams name="jdbc/database">
                 <parameter>
                    <name>user</name>
                    <value>usr</value>
                 </parameter>
                 <parameter>
                    <name>password</name>
                    <value>pas</value>
                 </parameter>
                 <parameter>
                    <name>driverClassName</name>
                    <value>org.postgresql.Driver</value>
                 </parameter>
                 <parameter>
                   <name>driverName</name>
                   <value>jdbc:postgresql:database</value>
                 </parameter>
             </ResourceParams>
    recompiled , restarted tomcat and got a null pointer message on my first call to con .

    Can anybody give some pointers ?

    thx
    FreeBSD , dooing more with less since 10 years ago
  2. #2
  3. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    I don't use Tomcat or Postgres, but it looks as if you are missing some things in your server.xml, namely a connection url and some others. Here is the Tomcat JNDI page. It has some stuff on PostgreS if you scroll down
    Tomcat JNDI
  4. #3
  5. No Profile Picture
    Mentat of IX
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Bucuresti / Toronto
    Posts
    112
    Rep Power
    12
    thanks , I pretty much did all of that step by step I wrote some code to use it in my application , as advised on that page :
    Code:
     try {
                   Context ctx = new InitialContext();
              if(ctx == null )
              err++;
              errorcode[err] = " | no initial context | ";
    
              DataSource ds =
                (DataSource)ctx.lookup(
                   "java:comp/env/jdbc/mydb");
    
          if (ds != null) {
            con = ds.getConnection();
    I ran it and errorcode showed : no initial context ...

    Any other ideeas on what might be wrong ?
  6. #4
  7. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    Can you post all of your server.xml?
  8. #5
  9. No Profile Picture
    Mentat of IX
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Bucuresti / Toronto
    Posts
    112
    Rep Power
    12
    nemi thanks a lot for helping me out .
    I have attached the entire file as i don't wanna flood this thread with xml

    if anybody that takes a look has ever worked with tomcat + SSL can you take a look at the commented out coyote SSL connector that crashes tomcat while starting up .
    Attached Files
    Last edited by zapa; June 3rd, 2003 at 01:19 PM.
    FreeBSD , dooing more with less since 10 years ago
  10. #6
  11. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    Do the Resource and ResourceParams tags for the postgres datasource need to go in the GlobalNamingSources tag at the top next to the other Resource tag? Try that and see what it does.
  12. #7
  13. No Profile Picture
    Mentat of IX
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Bucuresti / Toronto
    Posts
    112
    Rep Power
    12
    that's how I initially had it setup , then this other howto , today , was talking about putting them there ... i will try it one more time maybe something else i changed today might make it all work
  14. #8
  15. No Profile Picture
    Mentat of IX
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Bucuresti / Toronto
    Posts
    112
    Rep Power
    12
    hmm , i just caught a new exception , maybe i'm moving forward :
    Cannot load JDBC driver class 'null'
    this is from the code fragment i put a few posts up
  16. #9
  17. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    Good, It sounds as if it is trying to create the connection but cannot find the driver. This should be in a jar file you got from the postgres site. It needs to be in your web apps WEB-INF/lib dir.
  18. #10
  19. No Profile Picture
    Mentat of IX
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Bucuresti / Toronto
    Posts
    112
    Rep Power
    12
    hmmm , various tutorials have been talking about putting this in the JAVA_HOME/jre/ext folder or CATALINA_HOME/lib folder , some talk about the classpath , I have about 4 postgresql.jars on my box now in various places , but indeed i don't have one there

    let's see ...
    Edit : nope , that didn't doo it ... oh well i'll keep on trying various things and see if i can get it working
    Last edited by zapa; June 3rd, 2003 at 03:13 PM.
  20. #11
  21. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    You tried the CATALINA_HOME/lib dir? Also try the CATALINA_HOME/common/lib
  22. #12
  23. No Profile Picture
    Mentat of IX
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Bucuresti / Toronto
    Posts
    112
    Rep Power
    12
    I preety much put that jar everywhere

    anywais that was not the problem . I was lucky enough to find this thread which helped me :
    1) solve the problem
    2) realise that i wasn't by far the only one with the problem

    http://forum.java.sun.com/thread.jsp...essage=1746688

    thanks again for your efforts to help me out

    it seems that the real problem is the very noob-confusing server.xml sintax ( fix is on the last post of the first page , the rest of the thread just shows ppl complaining that they can't get it working )
    Last edited by zapa; June 3rd, 2003 at 04:05 PM.
  24. #13
  25. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    Odd, isn't that where you had it before and it wasn't working?
  26. #14
  27. No Profile Picture
    Mentat of IX
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Bucuresti / Toronto
    Posts
    112
    Rep Power
    12
    this was the actual problem :
    <Context path="/myapps" ......>

    <Resource name="jdbc/mydb" auth="Container" type...>
    the documentation wasn't too clear about what I should put in there , i never saw that explained , i just saw examples that left me wondering weather that was a directory name , a database name or a driver name

    now that i think about it some more , it might be that both places work , where i put it and where you sugested , and the only difference might be that one makes the pool available to all webapps while the other one makes the pool available to a single webapp .

    edit : and there was another problem with my server.xml , it didn't like the \\localhost:5432\freddy address for the database so i got it working directly with jdbcostgresql:freddy
    Last edited by zapa; June 3rd, 2003 at 04:32 PM.
  28. #15
  29. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    1
    Rep Power
    0

    Help Needed for Connection Pooling


    hai,

    I am new to tomcat. I am trying to setup connection pooling using postgres and tomcat. can you please send me ur server.xml and web.xml.

    Thanks a lot..!!

    Vraj

IMN logo majestic logo threadwatch logo seochat tools logo