Thread: a little disillusioned

a little disillusioned

From
"Frequency UnKnown"
Date:
well, my ploy failed. having never got a decent answer from any technical
forum, i had to try.

so back to the tried and tested method:

can anyone explain to me why tomcat 5 will not find org.postgresql.Driver
when it is definitely there?

i know this is a very broad question but i have covered the obvious things
like class path and such (which, i might add, is the worst part of Java
invented). the only thing that seems to work for me is to extract the
contents of the .JAR file into my $JAVAHOME. surely this is NOT the way to
do it - otherwise the package wouldn't even come as a JAR. in fact, i've got
plenty of other JARs working, such as the SmartUploader, SOAP handlers and
the like.

So what's the difference between me directly instantiating a class (which it
seems i can do) and calling Class.forName()/createInstance() (or whatever it
is) in terms of where Java looks for classes? as i said, the classpath for
my system, for java, and for tomcat are all pointed to the place where I
have put the JAR.

i'm running debian, if that helps.

Shelley Pants
Web Developer

PS: i will go elsewhere if i am in the wrong place too. is there a forum
more related to my topic?

_________________________________________________________________
Protect your inbox from harmful viruses with new ninemsn Premium. Click here
  http://ninemsn.com.au/premium/landing.asp


Re: a little disillusioned

From
Oliver Jowett
Date:
Frequency UnKnown wrote:
> well, my ploy failed. having never got a decent answer from any
> technical forum, i had to try.

I'm not sure what you mean here. To get a decent answer it helps to ask
a clear question.

> so back to the tried and tested method:
>
> can anyone explain to me why tomcat 5 will not find
> org.postgresql.Driver when it is definitely there?

Have you tried the Tomcat lists? Does whatever you're doing work with
other JDBC drivers if you change org.postgresql.Driver to their driver
implementation class?

> So what's the difference between me directly instantiating a class
> (which it seems i can do) and calling Class.forName()/createInstance()
> (or whatever it is) in terms of where Java looks for classes? as i said,
> the classpath for my system, for java, and for tomcat are all pointed to
> the place where I have put the JAR.

In theory there should be no difference between 'new foo()' and
'Class.forName("foo").newInstance()' other than in how exceptions are
reported (however note that the class you execute these code fragments
in becomes significant). However you haven't given us enough information
to go on here. At a minimum, what are the exact exceptions & stack
traces you see? Can you provide the code that does work vs. the code
that doesn't?

You mentioned an InstantiationException (or InstantiationError?) in your
previous mail. You should only get this if trying to instantiate an
abstract class or interface. This might happen if you're using a driver
jar that's built for an older JDBC version than the actual version being
used -- as the newer JDBC methods will have no implementation. (or do
you get an IncompatibleClassChangeError or AbstractMethodError in this
case? I forget..). But this shouldn't happen on instantiation of
org.postgresql.Driver itself, since that doesn't actually build any
version-dependent objects until connect() is called.

BTW, you shouldn't have to instantiate org.postgresql.Driver yourself --
just ensure the class is loaded (Class.forName("org.postgresql.Driver"))
and it'll be available via java.sql.DriverManager. Or is this
instantiation happening in the guts of Tomcat?

> i'm running debian, if that helps.

Check that you don't have a different version of the driver sitting
around somewhere elsewhere in the classpath, IIRC debian likes to
install jars into /usr/share/java, perhaps you have an older version there?

-O

Re: a little disillusioned

From
Jonathan Gold
Date:
i haven't used tomcat 5, but i know some stuff about tomcat 4, and it
sounds like it could pertain. you have to place a jar high enough up
in your tomcat directories so that any class which uses it (and, more
importantly, whichever class calls the Class.forName method) will be
in directories at that level or lower (for instance,
$CATALINA_HOME/common/libs). perhaps you aren't doing this, and you
have it too low (do you have different webapps using postgres? if so,
you can't have separate instances of the driver in
.../yourWebApp/WEB-INF/lib). for more, see the tomcat docs (ClassLoader
howto) and the tomcat lists for more specifics.

jon

On Wed, 21 Jan 2004, Frequency UnKnown wrote:

> well, my ploy failed. having never got a decent answer from any technical
> forum, i had to try.
>
> so back to the tried and tested method:
>
> can anyone explain to me why tomcat 5 will not find org.postgresql.Driver
> when it is definitely there?
>
> i know this is a very broad question but i have covered the obvious things
> like class path and such (which, i might add, is the worst part of Java
> invented). the only thing that seems to work for me is to extract the
> contents of the .JAR file into my $JAVAHOME. surely this is NOT the way to
> do it - otherwise the package wouldn't even come as a JAR. in fact, i've got
> plenty of other JARs working, such as the SmartUploader, SOAP handlers and
> the like.
>
> So what's the difference between me directly instantiating a class (which it
> seems i can do) and calling Class.forName()/createInstance() (or whatever it
> is) in terms of where Java looks for classes? as i said, the classpath for
> my system, for java, and for tomcat are all pointed to the place where I
> have put the JAR.
>
> i'm running debian, if that helps.
>
> Shelley Pants
> Web Developer
>
> PS: i will go elsewhere if i am in the wrong place too. is there a forum
> more related to my topic?
>
> _________________________________________________________________
> Protect your inbox from harmful viruses with new ninemsn Premium. Click here
>   http://ninemsn.com.au/premium/landing.asp
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings
>

Re: a little disillusioned

From
Paul Thomas
Date:
On 21/01/2004 05:12 Frequency UnKnown wrote:
> well, my ploy failed. having never got a decent answer from any
> technical forum, i had to try.
>
> so back to the tried and tested method:
>
> can anyone explain to me why tomcat 5 will not find
> org.postgresql.Driver when it is definitely there?
>
> i know this is a very broad question but i have covered the obvious
> things like class path and such (which, i might add, is the worst part
> of Java invented). the only thing that seems to work for me is to
> extract the contents of the .JAR file into my $JAVAHOME. surely this is
> NOT the way to do it - otherwise the package wouldn't even come as a
> JAR. in fact, i've got plenty of other JARs working, such as the
> SmartUploader, SOAP handlers and the like.
>
> So what's the difference between me directly instantiating a class
> (which it seems i can do) and calling Class.forName()/createInstance()
> (or whatever it is) in terms of where Java looks for classes? as i said,
> the classpath for my system, for java, and for tomcat are all pointed to
> the place where I have put the JAR.

Stay away from classpaths with Tomcat - it uses its own class loaders and
you can really confuse it if you have your jar in the classpath too. What
I do (on Tomcat 4.1) is put the driver in common/lib and use connection
pooling via JNDI (if you do this _do not_ include the driver in your app
as well). Have you tried this approach? Have you tried running your app
under Tomcat 4.1?

> i'm running debian, if that helps.

IMHO, running anything other than M$ helps ;)

> PS: i will go elsewhere if i am in the wrong place too. is there a forum
> more related to my topic?

Maybe the Tomcat people could help?

--
Paul Thomas
+------------------------------+---------------------------------------------+
| Thomas Micro Systems Limited | Software Solutions for the Smaller
Business |
| Computer Consultants         |
http://www.thomas-micro-systems-ltd.co.uk   |
+------------------------------+---------------------------------------------+

Re: a little disillusioned

From
nahum castro
Date:
 --- Frequency UnKnown <captainmofopants@hotmail.com>
escribió: > well, my ploy failed. having never got a
decent
> answer from any technical
> forum, i had to try.
>
> so back to the tried and tested method:
>
> can anyone explain to me why tomcat 5 will not find
> org.postgresql.Driver
> when it is definitely there?

I put the jdbc diver in /tomcat5/common/lib and works
perfect, perhaps the problem is in your classpath
please reviev this variable with
$set | less
as the user who runs tomcat.

I have the same problem recently on my mac and was a
corrupted jvm, some jars work and others not so I
reinstalled my system and now works perfect.

I use macos X 10.1.5 and fedora core 1 both with
tomcat 5.0.16 and postgresql 7.4.1.


=====
--
Nahum Castro
Leon, Guanajuato, Mexico
e-mail: pedro1_72@yahoo.com

_________________________________________________________
Do You Yahoo!?
La mejor conexión a internet y 25MB extra a tu correo por $100 al mes. http://net.yahoo.com.mx

Re: a little disillusioned

From
"Frequency UnKnown"
Date:
thanks so much to everyone who replied to my posts.

to clarify my previous position, i tried to goad users of the list into
replying by making some deliberately vacuous statements. sometimes this is
all that works. i apologise to everyone who is on a quite obviously active
and helpful list.

a number of people suggested that it was not necessary to instantiate the
class when using tomcat's pooling, however we are using our own pooling
beans which simply take text SQL and return Java objects (with the usual
hassles of opening connections, preparing statements, enumerating through
result sets etc. taken care of). if all else fails i will try this out, but
i would like to keep the site architecture the same as what the team is used
to.

we are using postgres 7.2. i notice we're up to 7.4 now. i have assumed the
changes would be minimal and this wouldn't cause the problem. have there
been any major changes to the way things are initialised?

yes my JAR is in /usr/share/java. tomcat is in /usr/share/jwsdp_1.3. i will
definitely try out the locations inside catalina/common/libs and also within
the tomcat webapp even though this is not generally encouraged. for getting
this application going (our first with tomcat5, living on a box all by
itself) that solution would be slightly better than extracting JARs.

thanks too for clarifying on the classpath: at least i can eliminate some of
the things i've been trying.

as for the tomcat people helping - well after seeing my first posts to this
list you can see how far i got there! if i get this problem sorted i will be
posting solutions to quite a few forums i am now a member of.


thanks a milliion again,
Shelley

_________________________________________________________________
Hot chart ringtones and polyphonics. Go to
http://ninemsn.com.au/mobilemania/default.asp


Re: a little disillusioned

From
David Wilbur
Date:
<fontfamily><param>Courier</param>

this may end up being a double post... my apologies if it is. i wasn't
registered and it stalled the post.


just wanted to mention that the person that was having tomcat issues
is not alone here.  unfortunately the docs as far as tomcat and
postgres boils down to some major hand waving re the two.  each
relying on the other to work things out for the other.  mysql getting
the best treatment from the tomcat people.


the os that i am running this on is:


mac os 10.3.2,


java version "1.4.1_01"

Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-99)

Java HotSpot(TM) Client VM (build 1.4.1_01-27, mixed mode)


tomcat was compiled from jakarta-tomcat-5.0.16-src.tar.gz where it
pulls all the files off the jakarta site.


postgresql 7.4.1


the following is a really trimmed down version of code from the tomcat
examples re jdbc connection pools:


      Context initCtx = new InitialContext();

      Context envCtx = (Context) initCtx.lookup("java:comp/env");

      DataSource ds = (DataSource)envCtx.lookup("jdbc/postgres");

      try {

          Connection conn = ds.getConnection();

          if(conn != null)  {

              foo = "Got Connection "+conn.toString();

              Statement stmt = conn.createStatement();

              ResultSet rst = stmt.executeQuery( "select id, foo, bar
from testdata" );

              if(rst.next()) {

                 foo=rst.getString(2);

                 bar=rst.getInt(3);

              }

              conn.close();

      } catch (SQLException e) {

          foo = "SQLException: " + e;

      }


results in a index.jsp showing this for foo...


SQLException: org.apache.commons.dbcp.SQLNestedException: Cannot load
JDBC driver class 'org.postgres.Driver', cause: org.postgres.Driver


when i go into the administration utility i find  a definition for the
data source where the web app is defined under


"/Tomcat Server/Catalina/localhost/DBTest/Data Sources"


<color><param>0000,0000,0000</param>JNDI Name       JDBC Driver Class</color>

<color><param>5553,1A18,8B89</param>jdbc/postgres</color>  
org.postgres.Driver


delving into that i see this:


JNDI Name:   jdbc/postgres

Data Source URL: jdbc:postgresql://127.0.0.1:5432/test

JDBC Driver Class: org.postgres.Driver

User Name: jakarta

Password: "the correct password"

Max. Active Connections: 20

Max. Idle Connections: 10

Max. Wait for Connection: 10000

Validation Query:



i modified the basic.java file that comes with the postgres jdbc
driver and ran it using the connection string above


jdbc:postgresql://127.0.0.1:5432/test


and that works fine using the same jar file that tomcat is using.



there is only one jar file in the tomcat directorys and it is located
at:


find $CATALINA_HOME -name "postgresql.jar"

/usr/local/jakarta/tomcat/common/lib/postgresql.jar


my class path has only ant and java home on it and i have checked to
see if the jar is there.


what i think would be really awesome is if one of you that have this
working could look at the tomcat "documentation" for setting  up
postgres and tomcat and maybe helping them and us by maybe making it
more intelligible... cause it is a mess as it is now.  in fact if
someone helps me work this out and they don't want to do it i will...
see:


http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-examples-howto.html


maybe even adding the same advice to the postgres jdbc examples so
that we would have a starting point that we knew was working for
someone...  this is a nice starting point, but... it might be nice to
add in something along the line of how to set up a java web server to
use postgres.


http://www.postgresql.org/docs/current/static/jdbc-datasource.html



i am suspecting that maybe is one of the xml files... either
<x-tad-bigger>$CATALINA_HOME/conf/server.xml  or the apps
WEB-INF/web.xml... but i really don't know for sure what i might have
wrong there.  in the mean time i guess i will try the mysql setup the
tomcat people define to see if that works... since i have to do that
too.


thanks in advance,

dave

</x-tad-bigger></fontfamily>
this may end up being a double post... my apologies if it is. i wasn't
registered and it stalled the post.

just wanted to mention that the person that was having tomcat issues is
not alone here.  unfortunately the docs as far as tomcat and postgres
boils down to some major hand waving re the two.  each relying on the
other to work things out for the other.  mysql getting the best
treatment from the tomcat people.

the os that i am running this on is:

mac os 10.3.2,

java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-99)
Java HotSpot(TM) Client VM (build 1.4.1_01-27, mixed mode)

tomcat was compiled from jakarta-tomcat-5.0.16-src.tar.gz where it
pulls all the files off the jakarta site.

postgresql 7.4.1

the following is a really trimmed down version of code from the tomcat
examples re jdbc connection pools:

       Context initCtx = new InitialContext();
       Context envCtx = (Context) initCtx.lookup("java:comp/env");
       DataSource ds = (DataSource)envCtx.lookup("jdbc/postgres");
       try {
           Connection conn = ds.getConnection();
           if(conn != null)  {
               foo = "Got Connection "+conn.toString();
               Statement stmt = conn.createStatement();
               ResultSet rst = stmt.executeQuery( "select id, foo, bar
from testdata" );
               if(rst.next()) {
                  foo=rst.getString(2);
                  bar=rst.getInt(3);
               }
               conn.close();
       } catch (SQLException e) {
           foo = "SQLException: " + e;
       }

results in a index.jsp showing this for foo...

SQLException: org.apache.commons.dbcp.SQLNestedException: Cannot load
JDBC driver class 'org.postgres.Driver', cause: org.postgres.Driver

when i go into the administration utility i find  a definition for the
data source where the web app is defined under

"/Tomcat Server/Catalina/localhost/DBTest/Data Sources"

JNDI Name       JDBC Driver Class
jdbc/postgres   org.postgres.Driver

delving into that i see this:

JNDI Name:   jdbc/postgres
Data Source URL: jdbc:postgresql://127.0.0.1:5432/test
JDBC Driver Class: org.postgres.Driver
User Name: jakarta
Password: "the correct password"
Max. Active Connections: 20
Max. Idle Connections: 10
Max. Wait for Connection: 10000
Validation Query:


i modified the basic.java file that comes with the postgres jdbc driver
and ran it using the connection string above

jdbc:postgresql://127.0.0.1:5432/test

and that works fine using the same jar file that tomcat is using.


there is only one jar file in the tomcat directorys and it is located
at:

find $CATALINA_HOME -name "postgresql.jar"
/usr/local/jakarta/tomcat/common/lib/postgresql.jar

my class path has only ant and java home on it and i have checked to
see if the jar is there.

what i think would be really awesome is if one of you that have this
working could look at the tomcat "documentation" for setting  up
postgres and tomcat and maybe helping them and us by maybe making it
more intelligible... cause it is a mess as it is now.  in fact if
someone helps me work this out and they don't want to do it i will...
see:

http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-
examples-howto.html

maybe even adding the same advice to the postgres jdbc examples so that
we would have a starting point that we knew was working for someone...
this is a nice starting point, but... it might be nice to add in
something along the line of how to set up a java web server to use
postgres.

http://www.postgresql.org/docs/current/static/jdbc-datasource.html


i am suspecting that maybe is one of the xml files... either
$CATALINA_HOME/conf/server.xml  or the apps WEB-INF/web.xml... but i
really don't know for sure what i might have wrong there.  in the mean
time i guess i will try the mysql setup the tomcat people define to see
if that works... since i have to do that too.

thanks in advance,
dave

Re: a little disillusioned

From
Paul Thomas
Date:
On 27/01/2004 19:07 David Wilbur wrote:
>
> this may end up being a double post... my apologies if it is. i wasn't
> registered and it stalled the post.
>
> just wanted to mention that the person that was having tomcat issues is
> not alone here.  unfortunately the docs as far as tomcat and postgres
> boils down to some major hand waving re the two.  each relying on the
> other to work things out for the other.  mysql getting the best
> treatment from the tomcat people.
>
> the os that i am running this on is:
>
> mac os 10.3.2,
>
> java version "1.4.1_01"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-99)
> Java HotSpot(TM) Client VM (build 1.4.1_01-27, mixed mode)
>
> tomcat was compiled from jakarta-tomcat-5.0.16-src.tar.gz where it
> pulls all the files off the jakarta site.
>
> postgresql 7.4.1
>
> the following is a really trimmed down version of code from the tomcat
> examples re jdbc connection pools:
>
>       Context initCtx = new InitialContext();
>       Context envCtx = (Context) initCtx.lookup("java:comp/env");
>       DataSource ds = (DataSource)envCtx.lookup("jdbc/postgres");
>       try {
>           Connection conn = ds.getConnection();
>           if(conn != null)  {
>               foo = "Got Connection "+conn.toString();
>               Statement stmt = conn.createStatement();
>               ResultSet rst = stmt.executeQuery( "select id, foo, bar
> from testdata" );
>               if(rst.next()) {
>                  foo=rst.getString(2);
>                  bar=rst.getInt(3);
>               }
>               conn.close();
>       } catch (SQLException e) {
>           foo = "SQLException: " + e;
>       }
>
> results in a index.jsp showing this for foo...
>
> SQLException: org.apache.commons.dbcp.SQLNestedException: Cannot load
> JDBC driver class 'org.postgres.Driver', cause: org.postgres.Driver
>
> when i go into the administration utility i find  a definition for the
> data source where the web app is defined under
>
> "/Tomcat Server/Catalina/localhost/DBTest/Data Sources"
>
> JNDI Name       JDBC Driver Class
> jdbc/postgres   org.postgres.Driver
>
> delving into that i see this:
>
> JNDI Name:   jdbc/postgres
> Data Source URL: jdbc:postgresql://127.0.0.1:5432/test
> JDBC Driver Class: org.postgres.Driver
> User Name: jakarta
> Password: "the correct password"
> Max. Active Connections: 20
> Max. Idle Connections: 10
> Max. Wait for Connection: 10000
> Validation Query:
>
>
> i modified the basic.java file that comes with the postgres jdbc driver
> and ran it using the connection string above
>
> jdbc:postgresql://127.0.0.1:5432/test
>
> and that works fine using the same jar file that tomcat is using.
>
>
> there is only one jar file in the tomcat directorys and it is located
> at:
>
> find $CATALINA_HOME -name "postgresql.jar"
> /usr/local/jakarta/tomcat/common/lib/postgresql.jar
>
> my class path has only ant and java home on it and i have checked to
> see if the jar is there.
>
> what i think would be really awesome is if one of you that have this
> working could look at the tomcat "documentation" for setting  up
> postgres and tomcat and maybe helping them and us by maybe making it
> more intelligible... cause it is a mess as it is now.  in fact if
> someone helps me work this out and they don't want to do it i will...
> see:
>
> http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-
> examples-howto.html
>
> maybe even adding the same advice to the postgres jdbc examples so that
> we would have a starting point that we knew was working for someone...
> this is a nice starting point, but... it might be nice to add in
> something along the line of how to set up a java web server to use
> postgres.


The Tomcat 5.0 docs gave the stupid (and I would have thought obvious)
typo that exists in the 4.1 doc for PostgreSQL. The web.xml res-ref-name
should refer to the matching name in the ResourceParams tag _not_ the
physical db name which appears in the JDBC url.

>
> http://www.postgresql.org/docs/current/static/jdbc-datasource.html
>
>
> i am suspecting that maybe is one of the xml files... either
> $CATALINA_HOME/conf/server.xml  or the apps WEB-INF/web.xml... but i
> really don't know for sure what i might have wrong there.  in the mean
> time i guess i will try the mysql setup the tomcat people define to see
> if that works... since i have to do that too.

FWIW, you don't really need to edit server.xml. Create a <app.,xml file
defining the context of you web app and put it in the webapps directory.
Here's a sample which also defines a JDBC realm.

<!-- Tomcat XML file for MyApp context -->
<!-- this file is to be placed in the webapps direcory -->

<!-- MyApp context -->
<Context path="/myapp"       docBase="myapp.war"         debug="0"
    reloadable="true"
  crossContext="true">

<Realm  className="org.apache.catalina.realm.JDBCRealm" debug="0"
        driverName="org.postgresql.Driver"
            digest="MD5"
     connectionURL="jdbc:postgresql://127.0.0.1:5432/my_physical_db"
    connectionName="dbuser" connectionPassword="dbpasswd"
         userTable="user_table" userNameCol="login_name"
userCredCol="password"
     userRoleTable="user_roles" roleNameCol="role" />

<Resource name="jdbc/aniceDB" auth="Container"
       type="javax.sql.DataSource"/>
     <ResourceParams name="jdbc/aniceDB">
    <parameter>
        <name>factory</name>

<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    </parameter>
    <parameter>
        <name>driverClassName</name>
        <value>org.postgresql.Driver</value>
    </parameter>
    <parameter>
        <name>url</name>

<value>jdbc:postgresql://127.0.0.1:5432/my_physical_db</value>
    </parameter>
    <parameter>
        <name>username</name>
        <value>dbuser</value>
    </parameter>
    <parameter>
        <name>password</name>
        <value>dbpasswd</value>
    </parameter>
    <parameter>
        <name>maxActive</name>
        <value>10</value>
    </parameter>
    <parameter>
        <name>maxIdle</name>
        <value>1</value>
    </parameter>
    <parameter>
        <name>maxWait</name>
        <value>30000</value>
    </parameter>
    <parameter>
        <name>removeAbandoned</name>
        <value>true</value>
    </parameter>
    <parameter>
        <name>removeAbandonedTimeout</name>
        <value>60</value>
    </parameter>
    <parameter>
        <name>logAbandoned</name>
        <value>true</value>
    </parameter>
     </ResourceParams>
</Context>

And here's part of the app's web.xml which defines the datasource


    <resource-ref>
        <description>
        Resource reference to a factory for java.sql.Connection
        instances that may be used for talking to a particular
        database that is configured in the server.xml file.
        </description>
        <res-ref-name>jdbc/aniceDB</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>


HTH

--
Paul Thomas
+------------------------------+---------------------------------------------+
| Thomas Micro Systems Limited | Software Solutions for the Smaller
Business |
| Computer Consultants         |
http://www.thomas-micro-systems-ltd.co.uk   |
+------------------------------+---------------------------------------------+

Re: a little disillusioned

From
David Wilbur
Date:
On Jan 27, 2004, at 3:01 PM, Paul Thomas wrote:

>
> On 27/01/2004 19:07 David Wilbur wrote:
>> maybe even adding the same advice to the postgres jdbc examples so
>> that  we would have a starting point that we knew was working for
>> someone...   this is a nice starting point, but... it might be nice
>> to add in  something along the line of how to set up a java web
>> server to use  postgres.
>
>
> The Tomcat 5.0 docs gave the stupid (and I would have thought obvious)
> typo that exists in the 4.1 doc for PostgreSQL. The web.xml
> res-ref-name should refer to the matching name in the ResourceParams
> tag _not_ the physical db name which appears in the JDBC url.

yep i saw that  here are my changes as i thought they should be:

more web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
     <!DOCTYPE web-app PUBLIC
     "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
     "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
   <description>PosgreSQL Test App</description>
   <resource-ref>
       <description>DB Connection</description>
       <res-ref-name>jdbc/postgres</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
   </resource-ref>
</web-app>


out of server.xml

                 <Context path="/pgtest" docBase="pgtest"  debug="5"
reloadable="true" crossContext="true">

                   <Logger
className="org.apache.catalina.logger.FileLogger"
                                          prefix="localhost_DBTest_log."
suffix=".txt"
                                          timestamp="true"/>

                   <Resource name="jdbc/postgres"  auth="Container"
type="javax.sql.DataSource"/>

                   <ResourceParams name="jdbc/postgres">
                         <parameter>
                           <name>factory</name>

<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
                         </parameter>

                         <parameter>
                           <name>maxActive</name>
                           <value>20</value>
                         </parameter>

                         <parameter>
                           <name>maxIdle</name>
                           <value>10</value>
                         </parameter>

                         <parameter>
                           <name>maxWait</name>
                           <value>10000</value>
                         </parameter>

                         <parameter>
                          <name>username</name>
                          <value>dbuser</value>
                         </parameter>

                         <parameter>
                          <name>password</name>
                          <value>dbpassword</value>
                         </parameter>

                         <parameter>
                            <name>driverClassName</name>
                            <value>org.postgres.Driver</value>
                         </parameter>

                         <parameter>
                           <name>url</name>

<value>jdbc:postgresql://127.0.0.1:5432/test</value>
                         </parameter>
                   </ResourceParams>
                 </Context>


>
>> http://www.postgresql.org/docs/current/static/jdbc-datasource.html
>> i am suspecting that maybe is one of the xml files... either
>> $CATALINA_HOME/conf/server.xml  or the apps WEB-INF/web.xml... but i
>> really don't know for sure what i might have wrong there.  in the
>> mean  time i guess i will try the mysql setup the tomcat people
>> define to see  if that works... since i have to do that too.
>
> FWIW, you don't really need to edit server.xml. Create a <app.,xml
> file defining the context of you web app and put it in the webapps
> directory. Here's a sample which also defines a JDBC realm.

yes, but i thought the whole point of the definition in the server.xml
file was to have it typed once there and then all you need in the
web.xml is the reference to it... that way an admin can make one change
and all that refer to the resource get changed...

thanks, looking  at the following...  they don't seem much different.

>
> <!-- Tomcat XML file for MyApp context -->
> <!-- this file is to be placed in the webapps direcory -->
>
> <!-- MyApp context -->
> <Context path="/myapp"       docBase="myapp.war"         debug="0"
>    reloadable="true"
>  crossContext="true">
>
> <Realm  className="org.apache.catalina.realm.JDBCRealm" debug="0"
>        driverName="org.postgresql.Driver"
>            digest="MD5"
>     connectionURL="jdbc:postgresql://127.0.0.1:5432/my_physical_db"
>    connectionName="dbuser" connectionPassword="dbpasswd"
>         userTable="user_table" userNameCol="login_name"
> userCredCol="password"
>     userRoleTable="user_roles" roleNameCol="role" />
>
> <Resource name="jdbc/aniceDB" auth="Container"
>       type="javax.sql.DataSource"/>     <ResourceParams
> name="jdbc/aniceDB">
>     <parameter>
>         <name>factory</name>
>          <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
>     </parameter>
>     <parameter>
>         <name>driverClassName</name>
>         <value>org.postgresql.Driver</value>
>     </parameter>
>     <parameter>
>         <name>url</name>
>          <value>jdbc:postgresql://127.0.0.1:5432/my_physical_db</value>
>     </parameter>
>     <parameter>
>         <name>username</name>
>         <value>dbuser</value>
>     </parameter>
>     <parameter>
>         <name>password</name>
>         <value>dbpasswd</value>
>     </parameter>
>     <parameter>
>         <name>maxActive</name>
>         <value>10</value>
>     </parameter>
>     <parameter>
>         <name>maxIdle</name>
>         <value>1</value>
>     </parameter>
>     <parameter>
>         <name>maxWait</name>
>         <value>30000</value>
>     </parameter>
>     <parameter>
>         <name>removeAbandoned</name>
>         <value>true</value>
>     </parameter>
>     <parameter>
>         <name>removeAbandonedTimeout</name>
>         <value>60</value>
>     </parameter>
>     <parameter>
>         <name>logAbandoned</name>
>         <value>true</value>
>     </parameter>
>     </ResourceParams> </Context>
>
> And here's part of the app's web.xml which defines the datasource
>
>
>     <resource-ref>
>         <description>
>         Resource reference to a factory for java.sql.Connection
>         instances that may be used for talking to a particular
>         database that is configured in the server.xml file.
>         </description>
>         <res-ref-name>jdbc/aniceDB</res-ref-name>
>         <res-type>javax.sql.DataSource</res-type>
>         <res-auth>Container</res-auth>
>     </resource-ref>
>
>
> HTH
>
> --
> Paul Thomas
> +------------------------------
> +---------------------------------------------+
> | Thomas Micro Systems Limited | Software Solutions for the Smaller
> Business |
> | Computer Consultants         |
> http://www.thomas-micro-systems-ltd.co.uk   |
> +------------------------------
> +---------------------------------------------+
>


Re: a little disillusioned

From
David Wilbur
Date:
i should also note that i just finished installing mysql and the mysql
jdbc driver and i do have this working for mysql, following verbatim
what is on this page

http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-
examples-howto.html

other then the error that Paul noted there isn't much different from
what i can tell for postgres.

On Jan 27, 2004, at 4:52 PM, David Wilbur wrote:

>
> On Jan 27, 2004, at 3:01 PM, Paul Thomas wrote:
>
>>
>> On 27/01/2004 19:07 David Wilbur wrote:
>>> maybe even adding the same advice to the postgres jdbc examples so
>>> that  we would have a starting point that we knew was working for
>>> someone...   this is a nice starting point, but... it might be nice
>>> to add in  something along the line of how to set up a java web
>>> server to use  postgres.
>>
>>
>> The Tomcat 5.0 docs gave the stupid (and I would have thought
>> obvious) typo that exists in the 4.1 doc for PostgreSQL. The web.xml
>> res-ref-name should refer to the matching name in the ResourceParams
>> tag _not_ the physical db name which appears in the JDBC url.
>
> yep i saw that  here are my changes as i thought they should be:
>
> more web.xml
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
>     <!DOCTYPE web-app PUBLIC
>     "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
>     "http://java.sun.com/dtd/web-app_2_3.dtd">
> <web-app>
>   <description>PosgreSQL Test App</description>
>   <resource-ref>
>       <description>DB Connection</description>
>       <res-ref-name>jdbc/postgres</res-ref-name>
>       <res-type>javax.sql.DataSource</res-type>
>       <res-auth>Container</res-auth>
>   </resource-ref>
> </web-app>
>
>
> out of server.xml
>
>                 <Context path="/pgtest" docBase="pgtest"  debug="5"
> reloadable="true" crossContext="true">
>
>                   <Logger
> className="org.apache.catalina.logger.FileLogger"
>
> prefix="localhost_DBTest_log." suffix=".txt"
>                                          timestamp="true"/>
>
>                   <Resource name="jdbc/postgres"  auth="Container"
> type="javax.sql.DataSource"/>
>
>                   <ResourceParams name="jdbc/postgres">
>                         <parameter>
>                           <name>factory</name>
>
> <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
>                         </parameter>
>
>                         <parameter>
>                           <name>maxActive</name>
>                           <value>20</value>
>                         </parameter>
>
>                         <parameter>
>                           <name>maxIdle</name>
>                           <value>10</value>
>                         </parameter>
>
>                         <parameter>
>                           <name>maxWait</name>
>                           <value>10000</value>
>                         </parameter>
>
>                         <parameter>
>                          <name>username</name>
>                          <value>dbuser</value>
>                         </parameter>
>
>                         <parameter>
>                          <name>password</name>
>                          <value>dbpassword</value>
>                         </parameter>
>
>                         <parameter>
>                            <name>driverClassName</name>
>                            <value>org.postgres.Driver</value>
>                         </parameter>
>
>                         <parameter>
>                           <name>url</name>
>
> <value>jdbc:postgresql://127.0.0.1:5432/test</value>
>                         </parameter>
>                   </ResourceParams>
>                 </Context>
>
>
>>
>>> http://www.postgresql.org/docs/current/static/jdbc-datasource.html
>>> i am suspecting that maybe is one of the xml files... either
>>> $CATALINA_HOME/conf/server.xml  or the apps WEB-INF/web.xml... but i
>>>  really don't know for sure what i might have wrong there.  in the
>>> mean  time i guess i will try the mysql setup the tomcat people
>>> define to see  if that works... since i have to do that too.
>>
>> FWIW, you don't really need to edit server.xml. Create a <app.,xml
>> file defining the context of you web app and put it in the webapps
>> directory. Here's a sample which also defines a JDBC realm.
>
> yes, but i thought the whole point of the definition in the server.xml
> file was to have it typed once there and then all you need in the
> web.xml is the reference to it... that way an admin can make one
> change and all that refer to the resource get changed...
>
> thanks, looking  at the following...  they don't seem much different.
>
>>
>> <!-- Tomcat XML file for MyApp context -->
>> <!-- this file is to be placed in the webapps direcory -->
>>
>> <!-- MyApp context -->
>> <Context path="/myapp"       docBase="myapp.war"         debug="0"
>>    reloadable="true"
>>  crossContext="true">
>>
>> <Realm  className="org.apache.catalina.realm.JDBCRealm" debug="0"
>>        driverName="org.postgresql.Driver"
>>            digest="MD5"
>>     connectionURL="jdbc:postgresql://127.0.0.1:5432/my_physical_db"
>>    connectionName="dbuser" connectionPassword="dbpasswd"
>>         userTable="user_table" userNameCol="login_name"
>> userCredCol="password"
>>     userRoleTable="user_roles" roleNameCol="role" />
>>
>> <Resource name="jdbc/aniceDB" auth="Container"
>>       type="javax.sql.DataSource"/>     <ResourceParams
>> name="jdbc/aniceDB">
>>     <parameter>
>>         <name>factory</name>
>>          <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
>>     </parameter>
>>     <parameter>
>>         <name>driverClassName</name>
>>         <value>org.postgresql.Driver</value>
>>     </parameter>
>>     <parameter>
>>         <name>url</name>
>>          <value>jdbc:postgresql://127.0.0.1:5432/my_physical_db</value>
>>     </parameter>
>>     <parameter>
>>         <name>username</name>
>>         <value>dbuser</value>
>>     </parameter>
>>     <parameter>
>>         <name>password</name>
>>         <value>dbpasswd</value>
>>     </parameter>
>>     <parameter>
>>         <name>maxActive</name>
>>         <value>10</value>
>>     </parameter>
>>     <parameter>
>>         <name>maxIdle</name>
>>         <value>1</value>
>>     </parameter>
>>     <parameter>
>>         <name>maxWait</name>
>>         <value>30000</value>
>>     </parameter>
>>     <parameter>
>>         <name>removeAbandoned</name>
>>         <value>true</value>
>>     </parameter>
>>     <parameter>
>>         <name>removeAbandonedTimeout</name>
>>         <value>60</value>
>>     </parameter>
>>     <parameter>
>>         <name>logAbandoned</name>
>>         <value>true</value>
>>     </parameter>
>>     </ResourceParams> </Context>
>>
>> And here's part of the app's web.xml which defines the datasource
>>
>>
>>     <resource-ref>
>>         <description>
>>         Resource reference to a factory for java.sql.Connection
>>         instances that may be used for talking to a particular
>>         database that is configured in the server.xml file.
>>         </description>
>>         <res-ref-name>jdbc/aniceDB</res-ref-name>
>>         <res-type>javax.sql.DataSource</res-type>
>>         <res-auth>Container</res-auth>
>>     </resource-ref>
>>
>>
>> HTH
>>
>> -- Paul Thomas
>> +------------------------------
>> +---------------------------------------------+
>> | Thomas Micro Systems Limited | Software Solutions for the Smaller
>> Business |
>> | Computer Consultants         |
>> http://www.thomas-micro-systems-ltd.co.uk   |
>> +------------------------------
>> +---------------------------------------------+
>>
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>


Re: a little disillusioned

From
David Wilbur
Date:
at the risk of being over kill ... i started over from scratch after
getting the mysql version working... on the first try.



here is the layout of the files in the project directory i have (and is
the same for the mysql project except it is DBTest)

./build
./build/index.jsp
./build/WEB-INF
./build/WEB-INF/classes
./build/WEB-INF/classes/foo
./build/WEB-INF/classes/foo/PGTest.class
./build/WEB-INF/lib
./build/WEB-INF/web.xml
./build.xml
./src
./src/foo
./src/foo/PGTest.java
./web
./web/index.jsp
./web/WEB-INF
./web/WEB-INF/web.xml


the build.xml file has one line changed in it from the one that the
tomcat doc suggests you use:

   <property name="catalina.home" value="/usr/local/jakarta/tomcat"/>


after i build i

cp -r build  $CATALINA_HOME/webapps/PGTest

and then

$CATALINA_HOME/bin/startup.sh

which results in the page saying that you are not connected... but in
reality is not finding the driver if i place a try block around
Connection conn = ds.getConnection();





here are the relevant files in the reworked version:


more ./web/WEB-INF/web.xml


<?xml version="1.0" encoding="ISO-8859-1"?>
     <!DOCTYPE web-app PUBLIC
     "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
     "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
   <description>PostgreSQL Test App</description>
   <resource-ref>
       <description>PG DB Connection</description>
       <res-ref-name>jdbc/TestPG</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
   </resource-ref>
</web-app>



more ./web/index.jsp


<html>
   <head>
     <title>PG Test</title>
   </head>
   <body>

   <%
     foo.PGTest tst = new foo.PGTest();
     tst.init();
   %>

   <h2>Results</h2>
     Foo <%= tst.getFoo() %><br/>
     Bar <%= tst.getBar() %>

   </body>
</html>



more ./src/foo/PGTest.java


package foo;

import javax.naming.*;
import javax.sql.*;
import java.sql.*;

public class PGTest {

   String foo = "Not Connected";
   int bar = -1;

   public void init() {
     try{
       Context ctx = new InitialContext();
       if(ctx == null )
           throw new Exception("Boom - No Context");

       DataSource ds =
             (DataSource)ctx.lookup(
                "java:comp/env/jdbc/TestPG");

       if (ds != null) {
         Connection conn = ds.getConnection();

         if(conn != null)  {
             foo = "Got Connection "+conn.toString();
             Statement stmt = conn.createStatement();
             ResultSet rst =
                 stmt.executeQuery(
                   "select id, foo, bar from testdata");
             if(rst.next()) {
                foo=rst.getString(2);
                bar=rst.getInt(3);
             }
             conn.close();
         }
       }
     }catch(Exception e) {
       e.printStackTrace();
     }
  }

  public String getFoo() { return foo; }
  public int getBar() { return bar;}
}



cat /usr/local/jakarta/tomcat/conf/server.xml

[snip]

<Context path="/PGTest" docBase="PGTest" debug="5" reloadable="true"
crossContext="true">

   <Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_PGTest_log." suffix=".txt" timestamp="true"/>

   <Resource name="jdbc/TestPG" auth="Container"
type="javax.sql.DataSource"/>

   <ResourceParams name="jdbc/TestPG">
     <parameter>
       <name>factory</name>
       <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
     </parameter>

     <parameter>
       <name>maxActive</name>
       <value>100</value>
     </parameter>

     <parameter>
       <name>maxIdle</name>
       <value>30</value>
     </parameter>

     <parameter>
       <name>maxWait</name>
       <value>10000</value>
     </parameter>

     <parameter>
      <name>username</name>
      <value>jakarta</value>
     </parameter>
     <parameter>
      <name>password</name>
      <value>tomcat</value>
     </parameter>

     <parameter>
        <name>driverClassName</name>
        <value>org.postgres.Driver</value>
     </parameter>

     <parameter>
       <name>url</name>
       <value>jdbc:postgresql://127.0.0.1:5432/test</value>
     </parameter>
   </ResourceParams>
</Context>

[snip]



here is the environment that the server is started with:



ANT_HOME=/usr/local/jakarta/ant
BASH=/bin/bash
BASH_VERSINFO=([0]="2" [1]="05b" [2]="0" [3]="1" [4]="release"
[5]="powerpc-apple-darwin7.0")
BASH_VERSION='2.05b.0(1)-release'
CATALINA_HOME=/usr/local/jakarta/tomcat
CLASSPATH=/Library/Java/Home/lib:/usr/local/jakarta/ant/lib
COLUMNS=141
DIRSTACK=()
DYLD_LIBRARY_PATH=/usr/local/lib:/usr/X11R6/lib:/usr/lib:/usr/local/
pgsql/lib:/usr/local/mysql/lib
EUID=504
GROUPS=()
HISTFILE=/Users/jakarta/.bash_history
HISTFILESIZE=500
HISTSIZE=500
HOME=/Users/jakarta
HOSTNAME=Halley.local
HOSTTYPE=powerpc
IFS=$' \t\n'
JAVA_HOME=/Library/Java/Home
LINES=76
MACHTYPE=powerpc-apple-darwin7.0
MAILCHECK=60
MANPATH=/usr/local/man:/usr/X11R6/man:/usr/share/man:/usr/local/pgsql/
man:/usr/local/mysql/man
MYSQL_DATA=/usr/local/mysql/var
MYSQL_HOME=/usr/local/mysql
OLDPWD=/Users/jakarta/Projects
OPTERR=1
OPTIND=1
OSTYPE=darwin7.0
PATH=/usr/local/bin:/usr/X11R6/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/
local/jakarta/ant/bin:/usr/local/pgsql/bin:/usr/local/mysql/bin
PGDATA=/usr/local/pgsql/data
PGHOME=/usr/local/pgsql
PIPESTATUS=([0]="0")
PPID=8049
PS1='\h:\w \u\$ '
PS2='> '
PS4='+ '
PWD=/Users/jakarta/Projects/jakarta
SHARED_SETUP_FILES=/usr/local/share/setup
SHELL=/bin/bash
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-
comments:monitor
SHLVL=1
TERM=xterm-color
UID=504
USER=jakarta
_=pgtest.junk/src/foo/DBTest.java



here is an example that demonstrates that out of tomcat that the
postgres.jar  that is in the proper place for tomcat works for a
regular java app and that the account and url in the xml files are
correct:

echo $CLASSPATH
/Library/Java/Home/lib:/usr/local/jakarta/ant/lib

export
CLASSPATH=${CLASSPATH}:/usr/local/jakarta/tomcat/common/lib/
postgresql.jar:.

javac -classpath ${CLASSPATH} example/basic.java
Note: example/basic.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.

java  example.basic jdbc:postgresql://127.0.0.1:5432/test jakarta tomcat
PostgreSQL basic test v6.3 rev 1

Connecting to Database URL = jdbc:postgresql://127.0.0.1:5432/test
Connected...Now creating a statement

Running tests:
Inserted row with oid 17246
Updated 4 rows
deleted 2 rows
performing a query
   a=3 b=8
   a=4 b=8
   a=4 b=2
   a=4 b=3
   a=4 b=4
performing another query
   a=3 b=8
   a=4 b=8
   a=4 b=2
   a=4 b=3
   a=4 b=4
performing a query limited to 3
   a=3 b=8
   a=4 b=8
   a=4 b=2
Now closing the connection


Re: a little disillusioned

From
Dave Cramer
Date:
attached is a working server.xml. The context that has the jdbc
datasource is /examples

I placed the postgresql.jar into common, however I expect it would work
in other places.

Dave


On Tue, 2004-01-27 at 20:46, David Wilbur wrote:
> at the risk of being over kill ... i started over from scratch after
> getting the mysql version working... on the first try.
>
>
>
> here is the layout of the files in the project directory i have (and is
> the same for the mysql project except it is DBTest)
>
> ./build
> ./build/index.jsp
> ./build/WEB-INF
> ./build/WEB-INF/classes
> ./build/WEB-INF/classes/foo
> ./build/WEB-INF/classes/foo/PGTest.class
> ./build/WEB-INF/lib
> ./build/WEB-INF/web.xml
> ./build.xml
> ./src
> ./src/foo
> ./src/foo/PGTest.java
> ./web
> ./web/index.jsp
> ./web/WEB-INF
> ./web/WEB-INF/web.xml
>
>
> the build.xml file has one line changed in it from the one that the
> tomcat doc suggests you use:
>
>    <property name="catalina.home" value="/usr/local/jakarta/tomcat"/>
>
>
> after i build i
>
> cp -r build  $CATALINA_HOME/webapps/PGTest
>
> and then
>
> $CATALINA_HOME/bin/startup.sh
>
> which results in the page saying that you are not connected... but in
> reality is not finding the driver if i place a try block around
> Connection conn = ds.getConnection();
>
>
>
>
>
> here are the relevant files in the reworked version:
>
>
> more ./web/WEB-INF/web.xml
>
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
>      <!DOCTYPE web-app PUBLIC
>      "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
>      "http://java.sun.com/dtd/web-app_2_3.dtd">
> <web-app>
>    <description>PostgreSQL Test App</description>
>    <resource-ref>
>        <description>PG DB Connection</description>
>        <res-ref-name>jdbc/TestPG</res-ref-name>
>        <res-type>javax.sql.DataSource</res-type>
>        <res-auth>Container</res-auth>
>    </resource-ref>
> </web-app>
>
>
>
> more ./web/index.jsp
>
>
> <html>
>    <head>
>      <title>PG Test</title>
>    </head>
>    <body>
>
>    <%
>      foo.PGTest tst = new foo.PGTest();
>      tst.init();
>    %>
>
>    <h2>Results</h2>
>      Foo <%= tst.getFoo() %><br/>
>      Bar <%= tst.getBar() %>
>
>    </body>
> </html>
>
>
>
> more ./src/foo/PGTest.java
>
>
> package foo;
>
> import javax.naming.*;
> import javax.sql.*;
> import java.sql.*;
>
> public class PGTest {
>
>    String foo = "Not Connected";
>    int bar = -1;
>
>    public void init() {
>      try{
>        Context ctx = new InitialContext();
>        if(ctx == null )
>            throw new Exception("Boom - No Context");
>
>        DataSource ds =
>              (DataSource)ctx.lookup(
>                 "java:comp/env/jdbc/TestPG");
>
>        if (ds != null) {
>          Connection conn = ds.getConnection();
>
>          if(conn != null)  {
>              foo = "Got Connection "+conn.toString();
>              Statement stmt = conn.createStatement();
>              ResultSet rst =
>                  stmt.executeQuery(
>                    "select id, foo, bar from testdata");
>              if(rst.next()) {
>                 foo=rst.getString(2);
>                 bar=rst.getInt(3);
>              }
>              conn.close();
>          }
>        }
>      }catch(Exception e) {
>        e.printStackTrace();
>      }
>   }
>
>   public String getFoo() { return foo; }
>   public int getBar() { return bar;}
> }
>
>
>
> cat /usr/local/jakarta/tomcat/conf/server.xml
>
> [snip]
>
> <Context path="/PGTest" docBase="PGTest" debug="5" reloadable="true"
> crossContext="true">
>
>    <Logger className="org.apache.catalina.logger.FileLogger"
> prefix="localhost_PGTest_log." suffix=".txt" timestamp="true"/>
>
>    <Resource name="jdbc/TestPG" auth="Container"
> type="javax.sql.DataSource"/>
>
>    <ResourceParams name="jdbc/TestPG">
>      <parameter>
>        <name>factory</name>
>        <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
>      </parameter>
>
>      <parameter>
>        <name>maxActive</name>
>        <value>100</value>
>      </parameter>
>
>      <parameter>
>        <name>maxIdle</name>
>        <value>30</value>
>      </parameter>
>
>      <parameter>
>        <name>maxWait</name>
>        <value>10000</value>
>      </parameter>
>
>      <parameter>
>       <name>username</name>
>       <value>jakarta</value>
>      </parameter>
>      <parameter>
>       <name>password</name>
>       <value>tomcat</value>
>      </parameter>
>
>      <parameter>
>         <name>driverClassName</name>
>         <value>org.postgres.Driver</value>
>      </parameter>
>
>      <parameter>
>        <name>url</name>
>        <value>jdbc:postgresql://127.0.0.1:5432/test</value>
>      </parameter>
>    </ResourceParams>
> </Context>
>
> [snip]
>
>
>
> here is the environment that the server is started with:
>
>
>
> ANT_HOME=/usr/local/jakarta/ant
> BASH=/bin/bash
> BASH_VERSINFO=([0]="2" [1]="05b" [2]="0" [3]="1" [4]="release"
> [5]="powerpc-apple-darwin7.0")
> BASH_VERSION='2.05b.0(1)-release'
> CATALINA_HOME=/usr/local/jakarta/tomcat
> CLASSPATH=/Library/Java/Home/lib:/usr/local/jakarta/ant/lib
> COLUMNS=141
> DIRSTACK=()
> DYLD_LIBRARY_PATH=/usr/local/lib:/usr/X11R6/lib:/usr/lib:/usr/local/
> pgsql/lib:/usr/local/mysql/lib
> EUID=504
> GROUPS=()
> HISTFILE=/Users/jakarta/.bash_history
> HISTFILESIZE=500
> HISTSIZE=500
> HOME=/Users/jakarta
> HOSTNAME=Halley.local
> HOSTTYPE=powerpc
> IFS=$' \t\n'
> JAVA_HOME=/Library/Java/Home
> LINES=76
> MACHTYPE=powerpc-apple-darwin7.0
> MAILCHECK=60
> MANPATH=/usr/local/man:/usr/X11R6/man:/usr/share/man:/usr/local/pgsql/
> man:/usr/local/mysql/man
> MYSQL_DATA=/usr/local/mysql/var
> MYSQL_HOME=/usr/local/mysql
> OLDPWD=/Users/jakarta/Projects
> OPTERR=1
> OPTIND=1
> OSTYPE=darwin7.0
> PATH=/usr/local/bin:/usr/X11R6/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/
> local/jakarta/ant/bin:/usr/local/pgsql/bin:/usr/local/mysql/bin
> PGDATA=/usr/local/pgsql/data
> PGHOME=/usr/local/pgsql
> PIPESTATUS=([0]="0")
> PPID=8049
> PS1='\h:\w \u\$ '
> PS2='> '
> PS4='+ '
> PWD=/Users/jakarta/Projects/jakarta
> SHARED_SETUP_FILES=/usr/local/share/setup
> SHELL=/bin/bash
> SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-
> comments:monitor
> SHLVL=1
> TERM=xterm-color
> UID=504
> USER=jakarta
> _=pgtest.junk/src/foo/DBTest.java
>
>
>
> here is an example that demonstrates that out of tomcat that the
> postgres.jar  that is in the proper place for tomcat works for a
> regular java app and that the account and url in the xml files are
> correct:
>
> echo $CLASSPATH
> /Library/Java/Home/lib:/usr/local/jakarta/ant/lib
>
> export
> CLASSPATH=${CLASSPATH}:/usr/local/jakarta/tomcat/common/lib/
> postgresql.jar:.
>
> javac -classpath ${CLASSPATH} example/basic.java
> Note: example/basic.java uses or overrides a deprecated API.
> Note: Recompile with -deprecation for details.
>
> java  example.basic jdbc:postgresql://127.0.0.1:5432/test jakarta tomcat
> PostgreSQL basic test v6.3 rev 1
>
> Connecting to Database URL = jdbc:postgresql://127.0.0.1:5432/test
> Connected...Now creating a statement
>
> Running tests:
> Inserted row with oid 17246
> Updated 4 rows
> deleted 2 rows
> performing a query
>    a=3 b=8
>    a=4 b=8
>    a=4 b=2
>    a=4 b=3
>    a=4 b=4
> performing another query
>    a=3 b=8
>    a=4 b=8
>    a=4 b=2
>    a=4 b=3
>    a=4 b=4
> performing a query limited to 3
>    a=3 b=8
>    a=4 b=8
>    a=4 b=2
> Now closing the connection
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
--
Dave Cramer
519 939 0336
ICQ # 1467551

Attachment

Re: a little disillusioned

From
Dave Cramer
Date:
Note, this is on a tomcat 4 server, and web.xml was not changed,

I also dropped your example code into the classes dir of the web
context, and a small test.jsp file in the jsp dir of the web context..


Also reading the tomcat docs:

NOTE:Third Party drivers should be in jarfiles, not zipfiles. Tomcat
only adds $CATALINA_HOME/common/lib/*.jar to the classpath.
        NOTE: Do not install these jarfiles in your /WEB-INF/lib, or
        $JAVA_HOME/jre/lib/ext, or anywhere else. You will experience
        problems if you install them anyplace other than
        $CATALINA_HOME/common/lib.


Dave

On Tue, 2004-01-27 at 23:45, Dave Cramer wrote:
> attached is a working server.xml. The context that has the jdbc
> datasource is /examples
>
> I placed the postgresql.jar into common, however I expect it would work
> in other places.
>
> Dave
>
>
> On Tue, 2004-01-27 at 20:46, David Wilbur wrote:
> > at the risk of being over kill ... i started over from scratch after
> > getting the mysql version working... on the first try.
> >
> >
> >
> > here is the layout of the files in the project directory i have (and is
> > the same for the mysql project except it is DBTest)
> >
> > ./build
> > ./build/index.jsp
> > ./build/WEB-INF
> > ./build/WEB-INF/classes
> > ./build/WEB-INF/classes/foo
> > ./build/WEB-INF/classes/foo/PGTest.class
> > ./build/WEB-INF/lib
> > ./build/WEB-INF/web.xml
> > ./build.xml
> > ./src
> > ./src/foo
> > ./src/foo/PGTest.java
> > ./web
> > ./web/index.jsp
> > ./web/WEB-INF
> > ./web/WEB-INF/web.xml
> >
> >
> > the build.xml file has one line changed in it from the one that the
> > tomcat doc suggests you use:
> >
> >    <property name="catalina.home" value="/usr/local/jakarta/tomcat"/>
> >
> >
> > after i build i
> >
> > cp -r build  $CATALINA_HOME/webapps/PGTest
> >
> > and then
> >
> > $CATALINA_HOME/bin/startup.sh
> >
> > which results in the page saying that you are not connected... but in
> > reality is not finding the driver if i place a try block around
> > Connection conn = ds.getConnection();
> >
> >
> >
> >
> >
> > here are the relevant files in the reworked version:
> >
> >
> > more ./web/WEB-INF/web.xml
> >
> >
> > <?xml version="1.0" encoding="ISO-8859-1"?>
> >      <!DOCTYPE web-app PUBLIC
> >      "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
> >      "http://java.sun.com/dtd/web-app_2_3.dtd">
> > <web-app>
> >    <description>PostgreSQL Test App</description>
> >    <resource-ref>
> >        <description>PG DB Connection</description>
> >        <res-ref-name>jdbc/TestPG</res-ref-name>
> >        <res-type>javax.sql.DataSource</res-type>
> >        <res-auth>Container</res-auth>
> >    </resource-ref>
> > </web-app>
> >
> >
> >
> > more ./web/index.jsp
> >
> >
> > <html>
> >    <head>
> >      <title>PG Test</title>
> >    </head>
> >    <body>
> >
> >    <%
> >      foo.PGTest tst = new foo.PGTest();
> >      tst.init();
> >    %>
> >
> >    <h2>Results</h2>
> >      Foo <%= tst.getFoo() %><br/>
> >      Bar <%= tst.getBar() %>
> >
> >    </body>
> > </html>
> >
> >
> >
> > more ./src/foo/PGTest.java
> >
> >
> > package foo;
> >
> > import javax.naming.*;
> > import javax.sql.*;
> > import java.sql.*;
> >
> > public class PGTest {
> >
> >    String foo = "Not Connected";
> >    int bar = -1;
> >
> >    public void init() {
> >      try{
> >        Context ctx = new InitialContext();
> >        if(ctx == null )
> >            throw new Exception("Boom - No Context");
> >
> >        DataSource ds =
> >              (DataSource)ctx.lookup(
> >                 "java:comp/env/jdbc/TestPG");
> >
> >        if (ds != null) {
> >          Connection conn = ds.getConnection();
> >
> >          if(conn != null)  {
> >              foo = "Got Connection "+conn.toString();
> >              Statement stmt = conn.createStatement();
> >              ResultSet rst =
> >                  stmt.executeQuery(
> >                    "select id, foo, bar from testdata");
> >              if(rst.next()) {
> >                 foo=rst.getString(2);
> >                 bar=rst.getInt(3);
> >              }
> >              conn.close();
> >          }
> >        }
> >      }catch(Exception e) {
> >        e.printStackTrace();
> >      }
> >   }
> >
> >   public String getFoo() { return foo; }
> >   public int getBar() { return bar;}
> > }
> >
> >
> >
> > cat /usr/local/jakarta/tomcat/conf/server.xml
> >
> > [snip]
> >
> > <Context path="/PGTest" docBase="PGTest" debug="5" reloadable="true"
> > crossContext="true">
> >
> >    <Logger className="org.apache.catalina.logger.FileLogger"
> > prefix="localhost_PGTest_log." suffix=".txt" timestamp="true"/>
> >
> >    <Resource name="jdbc/TestPG" auth="Container"
> > type="javax.sql.DataSource"/>
> >
> >    <ResourceParams name="jdbc/TestPG">
> >      <parameter>
> >        <name>factory</name>
> >        <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
> >      </parameter>
> >
> >      <parameter>
> >        <name>maxActive</name>
> >        <value>100</value>
> >      </parameter>
> >
> >      <parameter>
> >        <name>maxIdle</name>
> >        <value>30</value>
> >      </parameter>
> >
> >      <parameter>
> >        <name>maxWait</name>
> >        <value>10000</value>
> >      </parameter>
> >
> >      <parameter>
> >       <name>username</name>
> >       <value>jakarta</value>
> >      </parameter>
> >      <parameter>
> >       <name>password</name>
> >       <value>tomcat</value>
> >      </parameter>
> >
> >      <parameter>
> >         <name>driverClassName</name>
> >         <value>org.postgres.Driver</value>
> >      </parameter>
> >
> >      <parameter>
> >        <name>url</name>
> >        <value>jdbc:postgresql://127.0.0.1:5432/test</value>
> >      </parameter>
> >    </ResourceParams>
> > </Context>
> >
> > [snip]
> >
> >
> >
> > here is the environment that the server is started with:
> >
> >
> >
> > ANT_HOME=/usr/local/jakarta/ant
> > BASH=/bin/bash
> > BASH_VERSINFO=([0]="2" [1]="05b" [2]="0" [3]="1" [4]="release"
> > [5]="powerpc-apple-darwin7.0")
> > BASH_VERSION='2.05b.0(1)-release'
> > CATALINA_HOME=/usr/local/jakarta/tomcat
> > CLASSPATH=/Library/Java/Home/lib:/usr/local/jakarta/ant/lib
> > COLUMNS=141
> > DIRSTACK=()
> > DYLD_LIBRARY_PATH=/usr/local/lib:/usr/X11R6/lib:/usr/lib:/usr/local/
> > pgsql/lib:/usr/local/mysql/lib
> > EUID=504
> > GROUPS=()
> > HISTFILE=/Users/jakarta/.bash_history
> > HISTFILESIZE=500
> > HISTSIZE=500
> > HOME=/Users/jakarta
> > HOSTNAME=Halley.local
> > HOSTTYPE=powerpc
> > IFS=$' \t\n'
> > JAVA_HOME=/Library/Java/Home
> > LINES=76
> > MACHTYPE=powerpc-apple-darwin7.0
> > MAILCHECK=60
> > MANPATH=/usr/local/man:/usr/X11R6/man:/usr/share/man:/usr/local/pgsql/
> > man:/usr/local/mysql/man
> > MYSQL_DATA=/usr/local/mysql/var
> > MYSQL_HOME=/usr/local/mysql
> > OLDPWD=/Users/jakarta/Projects
> > OPTERR=1
> > OPTIND=1
> > OSTYPE=darwin7.0
> > PATH=/usr/local/bin:/usr/X11R6/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/
> > local/jakarta/ant/bin:/usr/local/pgsql/bin:/usr/local/mysql/bin
> > PGDATA=/usr/local/pgsql/data
> > PGHOME=/usr/local/pgsql
> > PIPESTATUS=([0]="0")
> > PPID=8049
> > PS1='\h:\w \u\$ '
> > PS2='> '
> > PS4='+ '
> > PWD=/Users/jakarta/Projects/jakarta
> > SHARED_SETUP_FILES=/usr/local/share/setup
> > SHELL=/bin/bash
> > SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-
> > comments:monitor
> > SHLVL=1
> > TERM=xterm-color
> > UID=504
> > USER=jakarta
> > _=pgtest.junk/src/foo/DBTest.java
> >
> >
> >
> > here is an example that demonstrates that out of tomcat that the
> > postgres.jar  that is in the proper place for tomcat works for a
> > regular java app and that the account and url in the xml files are
> > correct:
> >
> > echo $CLASSPATH
> > /Library/Java/Home/lib:/usr/local/jakarta/ant/lib
> >
> > export
> > CLASSPATH=${CLASSPATH}:/usr/local/jakarta/tomcat/common/lib/
> > postgresql.jar:.
> >
> > javac -classpath ${CLASSPATH} example/basic.java
> > Note: example/basic.java uses or overrides a deprecated API.
> > Note: Recompile with -deprecation for details.
> >
> > java  example.basic jdbc:postgresql://127.0.0.1:5432/test jakarta tomcat
> > PostgreSQL basic test v6.3 rev 1
> >
> > Connecting to Database URL = jdbc:postgresql://127.0.0.1:5432/test
> > Connected...Now creating a statement
> >
> > Running tests:
> > Inserted row with oid 17246
> > Updated 4 rows
> > deleted 2 rows
> > performing a query
> >    a=3 b=8
> >    a=4 b=8
> >    a=4 b=2
> >    a=4 b=3
> >    a=4 b=4
> > performing another query
> >    a=3 b=8
> >    a=4 b=8
> >    a=4 b=2
> >    a=4 b=3
> >    a=4 b=4
> > performing a query limited to 3
> >    a=3 b=8
> >    a=4 b=8
> >    a=4 b=2
> > Now closing the connection
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 4: Don't 'kill -9' the postmaster
> >
--
Dave Cramer
519 939 0336
ICQ # 1467551

Attachment

Re: a little disillusioned now tomcat 5

From
Dave Cramer
Date:
Ok, now I set this up for tomcat 5, and the config file that needs to be
modified is in Catalina/localhost/servlet-examples.xml

where servlet-examples is the context.

FWIW, I used the admin tools to set this up, and again the postgres.jar
was in the common/lib dir

Dave
On Wed, 2004-01-28 at 07:45, Dave Cramer wrote:
> Note, this is on a tomcat 4 server, and web.xml was not changed,
>
> I also dropped your example code into the classes dir of the web
> context, and a small test.jsp file in the jsp dir of the web context..
>
>
> Also reading the tomcat docs:
>
> NOTE:Third Party drivers should be in jarfiles, not zipfiles. Tomcat
> only adds $CATALINA_HOME/common/lib/*.jar to the classpath.
>         NOTE: Do not install these jarfiles in your /WEB-INF/lib, or
>         $JAVA_HOME/jre/lib/ext, or anywhere else. You will experience
>         problems if you install them anyplace other than
>         $CATALINA_HOME/common/lib.
>
>
> Dave
>
> On Tue, 2004-01-27 at 23:45, Dave Cramer wrote:
> > attached is a working server.xml. The context that has the jdbc
> > datasource is /examples
> >
> > I placed the postgresql.jar into common, however I expect it would work
> > in other places.
> >
> > Dave
> >
> >
> > On Tue, 2004-01-27 at 20:46, David Wilbur wrote:
> > > at the risk of being over kill ... i started over from scratch after
> > > getting the mysql version working... on the first try.
> > >
> > >
> > >
> > > here is the layout of the files in the project directory i have (and is
> > > the same for the mysql project except it is DBTest)
> > >
> > > ./build
> > > ./build/index.jsp
> > > ./build/WEB-INF
> > > ./build/WEB-INF/classes
> > > ./build/WEB-INF/classes/foo
> > > ./build/WEB-INF/classes/foo/PGTest.class
> > > ./build/WEB-INF/lib
> > > ./build/WEB-INF/web.xml
> > > ./build.xml
> > > ./src
> > > ./src/foo
> > > ./src/foo/PGTest.java
> > > ./web
> > > ./web/index.jsp
> > > ./web/WEB-INF
> > > ./web/WEB-INF/web.xml
> > >
> > >
> > > the build.xml file has one line changed in it from the one that the
> > > tomcat doc suggests you use:
> > >
> > >    <property name="catalina.home" value="/usr/local/jakarta/tomcat"/>
> > >
> > >
> > > after i build i
> > >
> > > cp -r build  $CATALINA_HOME/webapps/PGTest
> > >
> > > and then
> > >
> > > $CATALINA_HOME/bin/startup.sh
> > >
> > > which results in the page saying that you are not connected... but in
> > > reality is not finding the driver if i place a try block around
> > > Connection conn = ds.getConnection();
> > >
> > >
> > >
> > >
> > >
> > > here are the relevant files in the reworked version:
> > >
> > >
> > > more ./web/WEB-INF/web.xml
> > >
> > >
> > > <?xml version="1.0" encoding="ISO-8859-1"?>
> > >      <!DOCTYPE web-app PUBLIC
> > >      "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
> > >      "http://java.sun.com/dtd/web-app_2_3.dtd">
> > > <web-app>
> > >    <description>PostgreSQL Test App</description>
> > >    <resource-ref>
> > >        <description>PG DB Connection</description>
> > >        <res-ref-name>jdbc/TestPG</res-ref-name>
> > >        <res-type>javax.sql.DataSource</res-type>
> > >        <res-auth>Container</res-auth>
> > >    </resource-ref>
> > > </web-app>
> > >
> > >
> > >
> > > more ./web/index.jsp
> > >
> > >
> > > <html>
> > >    <head>
> > >      <title>PG Test</title>
> > >    </head>
> > >    <body>
> > >
> > >    <%
> > >      foo.PGTest tst = new foo.PGTest();
> > >      tst.init();
> > >    %>
> > >
> > >    <h2>Results</h2>
> > >      Foo <%= tst.getFoo() %><br/>
> > >      Bar <%= tst.getBar() %>
> > >
> > >    </body>
> > > </html>
> > >
> > >
> > >
> > > more ./src/foo/PGTest.java
> > >
> > >
> > > package foo;
> > >
> > > import javax.naming.*;
> > > import javax.sql.*;
> > > import java.sql.*;
> > >
> > > public class PGTest {
> > >
> > >    String foo = "Not Connected";
> > >    int bar = -1;
> > >
> > >    public void init() {
> > >      try{
> > >        Context ctx = new InitialContext();
> > >        if(ctx == null )
> > >            throw new Exception("Boom - No Context");
> > >
> > >        DataSource ds =
> > >              (DataSource)ctx.lookup(
> > >                 "java:comp/env/jdbc/TestPG");
> > >
> > >        if (ds != null) {
> > >          Connection conn = ds.getConnection();
> > >
> > >          if(conn != null)  {
> > >              foo = "Got Connection "+conn.toString();
> > >              Statement stmt = conn.createStatement();
> > >              ResultSet rst =
> > >                  stmt.executeQuery(
> > >                    "select id, foo, bar from testdata");
> > >              if(rst.next()) {
> > >                 foo=rst.getString(2);
> > >                 bar=rst.getInt(3);
> > >              }
> > >              conn.close();
> > >          }
> > >        }
> > >      }catch(Exception e) {
> > >        e.printStackTrace();
> > >      }
> > >   }
> > >
> > >   public String getFoo() { return foo; }
> > >   public int getBar() { return bar;}
> > > }
> > >
> > >
> > >
> > > cat /usr/local/jakarta/tomcat/conf/server.xml
> > >
> > > [snip]
> > >
> > > <Context path="/PGTest" docBase="PGTest" debug="5" reloadable="true"
> > > crossContext="true">
> > >
> > >    <Logger className="org.apache.catalina.logger.FileLogger"
> > > prefix="localhost_PGTest_log." suffix=".txt" timestamp="true"/>
> > >
> > >    <Resource name="jdbc/TestPG" auth="Container"
> > > type="javax.sql.DataSource"/>
> > >
> > >    <ResourceParams name="jdbc/TestPG">
> > >      <parameter>
> > >        <name>factory</name>
> > >        <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
> > >      </parameter>
> > >
> > >      <parameter>
> > >        <name>maxActive</name>
> > >        <value>100</value>
> > >      </parameter>
> > >
> > >      <parameter>
> > >        <name>maxIdle</name>
> > >        <value>30</value>
> > >      </parameter>
> > >
> > >      <parameter>
> > >        <name>maxWait</name>
> > >        <value>10000</value>
> > >      </parameter>
> > >
> > >      <parameter>
> > >       <name>username</name>
> > >       <value>jakarta</value>
> > >      </parameter>
> > >      <parameter>
> > >       <name>password</name>
> > >       <value>tomcat</value>
> > >      </parameter>
> > >
> > >      <parameter>
> > >         <name>driverClassName</name>
> > >         <value>org.postgres.Driver</value>
> > >      </parameter>
> > >
> > >      <parameter>
> > >        <name>url</name>
> > >        <value>jdbc:postgresql://127.0.0.1:5432/test</value>
> > >      </parameter>
> > >    </ResourceParams>
> > > </Context>
> > >
> > > [snip]
> > >
> > >
> > >
> > > here is the environment that the server is started with:
> > >
> > >
> > >
> > > ANT_HOME=/usr/local/jakarta/ant
> > > BASH=/bin/bash
> > > BASH_VERSINFO=([0]="2" [1]="05b" [2]="0" [3]="1" [4]="release"
> > > [5]="powerpc-apple-darwin7.0")
> > > BASH_VERSION='2.05b.0(1)-release'
> > > CATALINA_HOME=/usr/local/jakarta/tomcat
> > > CLASSPATH=/Library/Java/Home/lib:/usr/local/jakarta/ant/lib
> > > COLUMNS=141
> > > DIRSTACK=()
> > > DYLD_LIBRARY_PATH=/usr/local/lib:/usr/X11R6/lib:/usr/lib:/usr/local/
> > > pgsql/lib:/usr/local/mysql/lib
> > > EUID=504
> > > GROUPS=()
> > > HISTFILE=/Users/jakarta/.bash_history
> > > HISTFILESIZE=500
> > > HISTSIZE=500
> > > HOME=/Users/jakarta
> > > HOSTNAME=Halley.local
> > > HOSTTYPE=powerpc
> > > IFS=$' \t\n'
> > > JAVA_HOME=/Library/Java/Home
> > > LINES=76
> > > MACHTYPE=powerpc-apple-darwin7.0
> > > MAILCHECK=60
> > > MANPATH=/usr/local/man:/usr/X11R6/man:/usr/share/man:/usr/local/pgsql/
> > > man:/usr/local/mysql/man
> > > MYSQL_DATA=/usr/local/mysql/var
> > > MYSQL_HOME=/usr/local/mysql
> > > OLDPWD=/Users/jakarta/Projects
> > > OPTERR=1
> > > OPTIND=1
> > > OSTYPE=darwin7.0
> > > PATH=/usr/local/bin:/usr/X11R6/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/
> > > local/jakarta/ant/bin:/usr/local/pgsql/bin:/usr/local/mysql/bin
> > > PGDATA=/usr/local/pgsql/data
> > > PGHOME=/usr/local/pgsql
> > > PIPESTATUS=([0]="0")
> > > PPID=8049
> > > PS1='\h:\w \u\$ '
> > > PS2='> '
> > > PS4='+ '
> > > PWD=/Users/jakarta/Projects/jakarta
> > > SHARED_SETUP_FILES=/usr/local/share/setup
> > > SHELL=/bin/bash
> > > SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-
> > > comments:monitor
> > > SHLVL=1
> > > TERM=xterm-color
> > > UID=504
> > > USER=jakarta
> > > _=pgtest.junk/src/foo/DBTest.java
> > >
> > >
> > >
> > > here is an example that demonstrates that out of tomcat that the
> > > postgres.jar  that is in the proper place for tomcat works for a
> > > regular java app and that the account and url in the xml files are
> > > correct:
> > >
> > > echo $CLASSPATH
> > > /Library/Java/Home/lib:/usr/local/jakarta/ant/lib
> > >
> > > export
> > > CLASSPATH=${CLASSPATH}:/usr/local/jakarta/tomcat/common/lib/
> > > postgresql.jar:.
> > >
> > > javac -classpath ${CLASSPATH} example/basic.java
> > > Note: example/basic.java uses or overrides a deprecated API.
> > > Note: Recompile with -deprecation for details.
> > >
> > > java  example.basic jdbc:postgresql://127.0.0.1:5432/test jakarta tomcat
> > > PostgreSQL basic test v6.3 rev 1
> > >
> > > Connecting to Database URL = jdbc:postgresql://127.0.0.1:5432/test
> > > Connected...Now creating a statement
> > >
> > > Running tests:
> > > Inserted row with oid 17246
> > > Updated 4 rows
> > > deleted 2 rows
> > > performing a query
> > >    a=3 b=8
> > >    a=4 b=8
> > >    a=4 b=2
> > >    a=4 b=3
> > >    a=4 b=4
> > > performing another query
> > >    a=3 b=8
> > >    a=4 b=8
> > >    a=4 b=2
> > >    a=4 b=3
> > >    a=4 b=4
> > > performing a query limited to 3
> > >    a=3 b=8
> > >    a=4 b=8
> > >    a=4 b=2
> > > Now closing the connection
> > >
> > >
> > > ---------------------------(end of broadcast)---------------------------
> > > TIP 4: Don't 'kill -9' the postmaster
> > >
--
Dave Cramer
519 939 0336
ICQ # 1467551

Attachment

Re: a little disillusioned

From
David Wilbur
Date:
<fontfamily><param>Courier</param>

just wanted to mention that this person is not alone here.
unfortunately the docs as far as tomcat and postgres boils down to
some major hand waving.  each relying on the other to work things out
for the other.  mysql getting the best treatment from the tomcat
people.


the os that i am running this on is:


mac os 10.3.2,


java version "1.4.1_01"

Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-99)

Java HotSpot(TM) Client VM (build 1.4.1_01-27, mixed mode)


tomcat was compiled from jakarta-tomcat-5.0.16-src.tar.gz where it
pulls all the files off the jakarta site.


postgresql 7.4.1


the following is a really trimmed down version of code from the tomcat
examples re jdbc connection pools:


      Context initCtx = new InitialContext();

      Context envCtx = (Context) initCtx.lookup("java:comp/env");

      DataSource ds = (DataSource)envCtx.lookup("jdbc/postgres");

      try {

          Connection conn = ds.getConnection();

          if(conn != null)  {

              foo = "Got Connection "+conn.toString();

              Statement stmt = conn.createStatement();

              ResultSet rst = stmt.executeQuery( "select id, foo, bar
from testdata" );

              if(rst.next()) {

                 foo=rst.getString(2);

                 bar=rst.getInt(3);

              }

              conn.close();

      } catch (SQLException e) {

          foo = "SQLException: " + e;

      }


results in a index.jsp showing this for foo...


SQLException: org.apache.commons.dbcp.SQLNestedException: Cannot load
JDBC driver class 'org.postgres.Driver', cause: org.postgres.Driver


when i go into the administration utility i find  a definition for the
data source where the web app is defined under


"/Tomcat Server/Catalina/localhost/DBTest/Data Sources"


<color><param>0000,0000,0000</param>JNDI Name       JDBC Driver Class</color>

<color><param>5555,1A1A,8B8B</param>jdbc/postgres</color>  
org.postgres.Driver


delving into that i see this:


JNDI Name:   jdbc/postgres

Data Source URL: jdbc:postgresql://127.0.0.1:5432/test

JDBC Driver Class: org.postgres.Driver

User Name: jakarta

Password: "the correct password"

Max. Active Connections: 20

Max. Idle Connections: 10

Max. Wait for Connection: 10000

Validation Query:



i modified the basic.java file that comes with the postgres jdbc
driver and ran it using the connection string above


jdbc:postgresql://127.0.0.1:5432/test


and that works fine using the same jar file that tomcat is using.



there is only one jar file in the tomcat directorys and it is located
at:


find $CATALINA_HOME -name "postgresql.jar"

/usr/local/jakarta/tomcat/common/lib/postgresql.jar


my class path has only ant and java home on it and i have checked to
see if the jar is there.


what i think would be really awesome is if one of you that have this
working could look at the tomcat "documentation" for setting  up
postgres and tomcat and maybe helping them and us by maybe making it
more intelligible... cause it is a mess as it is now.  in fact if
someone helps me work this out and they don't want to do it i will...
see:


http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-examples-howto.html


maybe even adding the same advice to the postgres jdbc examples so
that we would have a starting point that we knew was working for
someone...  this is a nice starting point, but... it might be nice to
add in something along the line of how to set up a java web server to
use postgres.


http://www.postgresql.org/docs/current/static/jdbc-datasource.html



i am suspecting that it is one of the xml files... either
<x-tad-bigger>$CATALINA_HOME/conf/server.xml  or the apps
WEB-INF/web.xml... but i really don't know for sure what i might have
wrong there.


thanks in advance,

dave

</x-tad-bigger></fontfamily>
just wanted to mention that this person is not alone here.
unfortunately the docs as far as tomcat and postgres boils down to some
major hand waving.  each relying on the other to work things out for
the other.  mysql getting the best treatment from the tomcat people.

the os that i am running this on is:

mac os 10.3.2,

java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-99)
Java HotSpot(TM) Client VM (build 1.4.1_01-27, mixed mode)

tomcat was compiled from jakarta-tomcat-5.0.16-src.tar.gz where it
pulls all the files off the jakarta site.

postgresql 7.4.1

the following is a really trimmed down version of code from the tomcat
examples re jdbc connection pools:

       Context initCtx = new InitialContext();
       Context envCtx = (Context) initCtx.lookup("java:comp/env");
       DataSource ds = (DataSource)envCtx.lookup("jdbc/postgres");
       try {
           Connection conn = ds.getConnection();
           if(conn != null)  {
               foo = "Got Connection "+conn.toString();
               Statement stmt = conn.createStatement();
               ResultSet rst = stmt.executeQuery( "select id, foo, bar
from testdata" );
               if(rst.next()) {
                  foo=rst.getString(2);
                  bar=rst.getInt(3);
               }
               conn.close();
       } catch (SQLException e) {
           foo = "SQLException: " + e;
       }

results in a index.jsp showing this for foo...

SQLException: org.apache.commons.dbcp.SQLNestedException: Cannot load
JDBC driver class 'org.postgres.Driver', cause: org.postgres.Driver

when i go into the administration utility i find  a definition for the
data source where the web app is defined under

"/Tomcat Server/Catalina/localhost/DBTest/Data Sources"

JNDI Name       JDBC Driver Class
jdbc/postgres   org.postgres.Driver

delving into that i see this:

JNDI Name:   jdbc/postgres
Data Source URL: jdbc:postgresql://127.0.0.1:5432/test
JDBC Driver Class: org.postgres.Driver
User Name: jakarta
Password: "the correct password"
Max. Active Connections: 20
Max. Idle Connections: 10
Max. Wait for Connection: 10000
Validation Query:


i modified the basic.java file that comes with the postgres jdbc driver
and ran it using the connection string above

jdbc:postgresql://127.0.0.1:5432/test

and that works fine using the same jar file that tomcat is using.


there is only one jar file in the tomcat directorys and it is located
at:

find $CATALINA_HOME -name "postgresql.jar"
/usr/local/jakarta/tomcat/common/lib/postgresql.jar

my class path has only ant and java home on it and i have checked to
see if the jar is there.

what i think would be really awesome is if one of you that have this
working could look at the tomcat "documentation" for setting  up
postgres and tomcat and maybe helping them and us by maybe making it
more intelligible... cause it is a mess as it is now.  in fact if
someone helps me work this out and they don't want to do it i will...
see:

http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-
examples-howto.html

maybe even adding the same advice to the postgres jdbc examples so that
we would have a starting point that we knew was working for someone...
this is a nice starting point, but... it might be nice to add in
something along the line of how to set up a java web server to use
postgres.

http://www.postgresql.org/docs/current/static/jdbc-datasource.html


i am suspecting that it is one of the xml files... either
$CATALINA_HOME/conf/server.xml  or the apps WEB-INF/web.xml... but i
really don't know for sure what i might have wrong there.

thanks in advance,
dave

Re: a little disillusioned

From
Dave Cramer
Date:
David,

See my previous posts I included files to set it up

Dave
On Mon, 2004-01-26 at 21:01, David Wilbur wrote:
> <fontfamily><param>Courier</param>
>
> just wanted to mention that this person is not alone here.
> unfortunately the docs as far as tomcat and postgres boils down to
> some major hand waving.  each relying on the other to work things out
> for the other.  mysql getting the best treatment from the tomcat
> people.
>
>
> the os that i am running this on is:
>
>
> mac os 10.3.2,
>
>
> java version "1.4.1_01"
>
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-99)
>
> Java HotSpot(TM) Client VM (build 1.4.1_01-27, mixed mode)
>
>
> tomcat was compiled from jakarta-tomcat-5.0.16-src.tar.gz where it
> pulls all the files off the jakarta site.
>
>
> postgresql 7.4.1
>
>
> the following is a really trimmed down version of code from the tomcat
> examples re jdbc connection pools:
>
>
>       Context initCtx = new InitialContext();
>
>       Context envCtx = (Context) initCtx.lookup("java:comp/env");
>
>       DataSource ds = (DataSource)envCtx.lookup("jdbc/postgres");
>
>       try {
>
>           Connection conn = ds.getConnection();
>
>           if(conn != null)  {
>
>               foo = "Got Connection "+conn.toString();
>
>               Statement stmt = conn.createStatement();
>
>               ResultSet rst = stmt.executeQuery( "select id, foo, bar
> from testdata" );
>
>               if(rst.next()) {
>
>                  foo=rst.getString(2);
>
>                  bar=rst.getInt(3);
>
>               }
>
>               conn.close();
>
>       } catch (SQLException e) {
>
>           foo = "SQLException: " + e;
>
>       }
>
>
> results in a index.jsp showing this for foo...
>
>
> SQLException: org.apache.commons.dbcp.SQLNestedException: Cannot load
> JDBC driver class 'org.postgres.Driver', cause: org.postgres.Driver
>
>
> when i go into the administration utility i find  a definition for the
> data source where the web app is defined under
>
>
> "/Tomcat Server/Catalina/localhost/DBTest/Data Sources"
>
>
> <color><param>0000,0000,0000</param>JNDI Name       JDBC Driver Class</color>
>
> <color><param>5555,1A1A,8B8B</param>jdbc/postgres</color>
> org.postgres.Driver
>
>
> delving into that i see this:
>
>
> JNDI Name:   jdbc/postgres
>
> Data Source URL: jdbc:postgresql://127.0.0.1:5432/test
>
> JDBC Driver Class: org.postgres.Driver
>
> User Name: jakarta
>
> Password: "the correct password"
>
> Max. Active Connections: 20
>
> Max. Idle Connections: 10
>
> Max. Wait for Connection: 10000
>
> Validation Query:
>
>
>
> i modified the basic.java file that comes with the postgres jdbc
> driver and ran it using the connection string above
>
>
> jdbc:postgresql://127.0.0.1:5432/test
>
>
> and that works fine using the same jar file that tomcat is using.
>
>
>
> there is only one jar file in the tomcat directorys and it is located
> at:
>
>
> find $CATALINA_HOME -name "postgresql.jar"
>
> /usr/local/jakarta/tomcat/common/lib/postgresql.jar
>
>
> my class path has only ant and java home on it and i have checked to
> see if the jar is there.
>
>
> what i think would be really awesome is if one of you that have this
> working could look at the tomcat "documentation" for setting  up
> postgres and tomcat and maybe helping them and us by maybe making it
> more intelligible... cause it is a mess as it is now.  in fact if
> someone helps me work this out and they don't want to do it i will...
> see:
>
>
> http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-examples-howto.html
>
>
> maybe even adding the same advice to the postgres jdbc examples so
> that we would have a starting point that we knew was working for
> someone...  this is a nice starting point, but... it might be nice to
> add in something along the line of how to set up a java web server to
> use postgres.
>
>
> http://www.postgresql.org/docs/current/static/jdbc-datasource.html
>
>
>
> i am suspecting that it is one of the xml files... either
> <x-tad-bigger>$CATALINA_HOME/conf/server.xml  or the apps
> WEB-INF/web.xml... but i really don't know for sure what i might have
> wrong there.
>
>
> thanks in advance,
>
> dave
>
> </x-tad-bigger></fontfamily>
--
Dave Cramer
519 939 0336
ICQ # 14675561


Re: a little disillusioned

From
David Wilbur
Date:

this is weird... the list is saying that i sent this yesterday... but
i originally sent it as you can see on the 26th.  ie: this is a repeat
post that i didn't do.  it even thinks of it's self as being from
headers as sent  <bold><color><param>0000,0000,0000</param>Date:
</color></bold><color><param>0000,0000,0000</param>    </color>January
26, 2004 7:01:08 PM MST  even thou it was received yesterday (for the
2nd time)


anyone know how this happened?  in fact i wasn't able to read mail
since the original post so i couldn't have posted this yesterday. does
the list manager duplicate send from time to time?




btw the problem was that i was missing the "ql" in the driver
reference. /blush  ie:  i had: org.postgres.Driver when i should have
had  org.postgresql.Driver  it always seems to be simple things
overlooked.


thanks to Dave Cramer for all his useful comments and JariP too.


david



On Jan 26, 2004, at 7:01 PM, David Wilbur wrote:


<excerpt><fontfamily><param>Courier</param>

just wanted to mention that this person is not alone here.
unfortunately the docs as far as tomcat and postgres boils down to
some major hand waving.  each relying on the other to work things out
for the other.  mysql getting the best treatment from the tomcat
people.


the os that i am running this on is:


mac os 10.3.2,


java version "1.4.1_01"

Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-99)

Java HotSpot(TM) Client VM (build 1.4.1_01-27, mixed mode)


tomcat was compiled from jakarta-tomcat-5.0.16-src.tar.gz where it
pulls all the files off the jakarta site.


postgresql 7.4.1


the following is a really trimmed down version of code from the tomcat
examples re jdbc connection pools:


      Context initCtx = new InitialContext();

      Context envCtx = (Context) initCtx.lookup("java:comp/env");

      DataSource ds = (DataSource)envCtx.lookup("jdbc/postgres");

      try {

          Connection conn = ds.getConnection();

          if(conn != null)  {

              foo = "Got Connection "+conn.toString();

              Statement stmt = conn.createStatement();

              ResultSet rst = stmt.executeQuery( "select id, foo, bar
from testdata" );

              if(rst.next()) {

                 foo=rst.getString(2);

                 bar=rst.getInt(3);

              }

              conn.close();

      } catch (SQLException e) {

          foo = "SQLException: " + e;

      }


results in a index.jsp showing this for foo...


SQLException: org.apache.commons.dbcp.SQLNestedException: Cannot load
JDBC driver class 'org.postgres.Driver', cause: org.postgres.Driver


when i go into the administration utility i find  a definition for the
data source where the web app is defined under


"/Tomcat Server/Catalina/localhost/DBTest/Data Sources"


<color><param>0000,0000,0000</param>JNDI Name       JDBC Driver Class</color>

<color><param>5554,1A19,8B8A</param>jdbc/postgres</color>  
org.postgres.Driver


delving into that i see this:


JNDI Name:   jdbc/postgres

Data Source URL: jdbc:postgresql://127.0.0.1:5432/test

JDBC Driver Class: org.postgres.Driver

User Name: jakarta

Password: "the correct password"

Max. Active Connections: 20

Max. Idle Connections: 10

Max. Wait for Connection: 10000

Validation Query:



i modified the basic.java file that comes with the postgres jdbc
driver and ran it using the connection string above


jdbc:postgresql://127.0.0.1:5432/test


and that works fine using the same jar file that tomcat is using.



there is only one jar file in the tomcat directorys and it is located
at:


find $CATALINA_HOME -name "postgresql.jar"

/usr/local/jakarta/tomcat/common/lib/postgresql.jar


my class path has only ant and java home on it and i have checked to
see if the jar is there.


what i think would be really awesome is if one of you that have this
working could look at the tomcat "documentation" for setting  up
postgres and tomcat and maybe helping them and us by maybe making it
more intelligible... cause it is a mess as it is now.  in fact if
someone helps me work this out and they don't want to do it i will...
see:


http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-examples-howto.html


maybe even adding the same advice to the postgres jdbc examples so
that we would have a starting point that we knew was working for
someone...  this is a nice starting point, but... it might be nice to
add in something along the line of how to set up a java web server to
use postgres.


http://www.postgresql.org/docs/current/static/jdbc-datasource.html



i am suspecting that it is one of the xml files... either
<x-tad-bigger>$CATALINA_HOME/conf/server.xml  or the apps
WEB-INF/web.xml... but i really don't know for sure what i might have
wrong there.


thanks in advance,

dave

</x-tad-bigger></fontfamily></excerpt>
this is weird... the list is saying that i sent this yesterday... but i
originally sent it as you can see on the 26th.  ie: this is a repeat
post that i didn't do.  it even thinks of it's self as being from
headers as sent  Date:     January 26, 2004 7:01:08 PM MST  even thou it
was received yesterday (for the 2nd time)

anyone know how this happened?  in fact i wasn't able to read mail
since the original post so i couldn't have posted this yesterday. does
the list manager duplicate send from time to time?



btw the problem was that i was missing the "ql" in the driver
reference. /blush  ie:  i had: org.postgres.Driver when i should have
had  org.postgresql.Driver  it always seems to be simple things
overlooked.

thanks to Dave Cramer for all his useful comments and JariP too.

david


On Jan 26, 2004, at 7:01 PM, David Wilbur wrote:

>
> just wanted to mention that this person is not alone here.
> unfortunately the docs as far as tomcat and postgres boils down to
> some major hand waving.  each relying on the other to work things out
> for the other.  mysql getting the best treatment from the tomcat
> people.
>
> the os that i am running this on is:
>
> mac os 10.3.2,
>
> java version "1.4.1_01"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-99)
> Java HotSpot(TM) Client VM (build 1.4.1_01-27, mixed mode)
>
> tomcat was compiled from jakarta-tomcat-5.0.16-src.tar.gz where it
> pulls all the files off the jakarta site.
>
> postgresql 7.4.1
>
> the following is a really trimmed down version of code from the tomcat
> examples re jdbc connection pools:
>
>       Context initCtx = new InitialContext();
>       Context envCtx = (Context) initCtx.lookup("java:comp/env");
>       DataSource ds = (DataSource)envCtx.lookup("jdbc/postgres");
>       try {
>           Connection conn = ds.getConnection();
>           if(conn != null)  {
>               foo = "Got Connection "+conn.toString();
>               Statement stmt = conn.createStatement();
>               ResultSet rst = stmt.executeQuery( "select id, foo, bar
> from testdata" );
>               if(rst.next()) {
>                  foo=rst.getString(2);
>                  bar=rst.getInt(3);
>               }
>               conn.close();
>       } catch (SQLException e) {
>           foo = "SQLException: " + e;
>       }
>
> results in a index.jsp showing this for foo...
>
> SQLException: org.apache.commons.dbcp.SQLNestedException: Cannot load
> JDBC driver class 'org.postgres.Driver', cause: org.postgres.Driver
>
> when i go into the administration utility i find  a definition for the
> data source where the web app is defined under
>
> "/Tomcat Server/Catalina/localhost/DBTest/Data Sources"
>
> JNDI Name       JDBC Driver Class
> jdbc/postgres   org.postgres.Driver
>
> delving into that i see this:
>
> JNDI Name:   jdbc/postgres
> Data Source URL: jdbc:postgresql://127.0.0.1:5432/test
> JDBC Driver Class: org.postgres.Driver
> User Name: jakarta
> Password: "the correct password"
> Max. Active Connections: 20
> Max. Idle Connections: 10
> Max. Wait for Connection: 10000
> Validation Query:
>
>
> i modified the basic.java file that comes with the postgres jdbc
> driver and ran it using the connection string above
>
> jdbc:postgresql://127.0.0.1:5432/test
>
> and that works fine using the same jar file that tomcat is using.
>
>
> there is only one jar file in the tomcat directorys and it is located
> at:
>
> find $CATALINA_HOME -name "postgresql.jar"
> /usr/local/jakarta/tomcat/common/lib/postgresql.jar
>
> my class path has only ant and java home on it and i have checked to
> see if the jar is there.
>
> what i think would be really awesome is if one of you that have this
> working could look at the tomcat "documentation" for setting  up
> postgres and tomcat and maybe helping them and us by maybe making it
> more intelligible... cause it is a mess as it is now.  in fact if
> someone helps me work this out and they don't want to do it i will...
> see:
>
> http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-
> examples-howto.html
>
> maybe even adding the same advice to the postgres jdbc examples so
> that we would have a starting point that we knew was working for
> someone...  this is a nice starting point, but... it might be nice to
> add in something along the line of how to set up a java web server to
> use postgres.
>
> http://www.postgresql.org/docs/current/static/jdbc-datasource.html
>
>
> i am suspecting that it is one of the xml files... either
> $CATALINA_HOME/conf/server.xml  or the apps WEB-INF/web.xml... but i
> really don't know for sure what i might have wrong there.
>
> thanks in advance,
> dave