You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Paul Salazar <pa...@testspectrum.com> on 2002/09/20 18:10:41 UTC

Postgresql DataSource Tomcat 4.1 SQLException

Hi,

I am trying to setup a postgresql datasource on tomcat 4.1 with much
frustration.
I have read all the threads out there concerning this matter and I can't
see to
find anyone who has a working example. What I have is this:

Redhat 7.2 server running:
Postgresql 7.2
Tomcat 4.1

I have a working Tomcat app that can connect to the Db and perform
queries when manually loading the driver
'Class.forName("org.postgresql.Driver");
and then doing a getConnection using the URL, Name, Password.

But when trying to get a connection using a Datasource, as in,

Context ctx = new InitialContext();
Context envctx = (Context)ctx.lookup("java:/comp/env");
DataSource ds = (DataSource)envctx.lookup("jdbc/postgres"); //jndi name
of the datasource
Connection conn = ds.getConnection();

the getConnection() statement throws an SQLException: Cannot load JDBC
driver class 'null'

I have gone over all the server.xml and web.xml files with a fine tooth
comb and assure
you that is not the problem. I have also tried using the jxDBCon drivers
with the same
results. I have come to the conclusion that it must be a tomcat problem.
Has anyone
gotten this to work with this config??

Paul Salazar


Re: Postgresql DataSource Tomcat 4.1 SQLException

Posted by Alfonso Martinez <tr...@linuxcenter.com.mx>.
Hi Paul, 

I tried your configuration and worked fine. The only thing I changed was the url to jdbc:postgresql://localhost/mydatabase  (also username and password of course).

I am almost sure that your problem should be in your classpath. I have had the same error before when my classpath was wrong. Remember that including the directory of the driver is not enough. You must make a reference to the actual file, in my case /usr/share/pgsql/jdbc7.1-1.2.jar. Copying the driver to your $CATALINA_HOME/common/lib should also work.

Any other ideas? Let me know if the problem persist. 

Jose Alfonso



On Mon, Sep 23, 2002 at 07:54:29AM -0500, Paul Salazar wrote:
> Alfonso,
> 
> Any help is appreciated.
> Here they are:
> 
> server.xml
> ----------
>     <Resource auth="Container" name="jdbc/postgres" scope="Shareable" type="javax.sql.DataSource"/>
>     <ResourceParams name="jdbc/postgres">
>       <parameter>
>         <name>url</name>
>         <value>jdbc:postgresql://roach/testdb</value>
>       </parameter>
>       <parameter>
>         <name>validationQuery</name>
>         <value></value>
>       </parameter>
>       <parameter>
>         <name>maxIdle</name>
>         <value>10</value>
>       </parameter>
>       <parameter>
>         <name>maxActive</name>
>         <value>20</value>
>       </parameter>
>       <parameter>
>         <name>driverClassName</name>
>         <value>org.postgresql.Driver</value>
>       </parameter>
>       <parameter>
>         <name>maxWait</name>
>         <value>-1</value>
>       </parameter>
>       <parameter>
>         <name>username</name>
>         <value>******</value>
>       </parameter>
>       <parameter>
>         <name>factory</name>
>         <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
>       </parameter>
>       <parameter>
>         <name>password</name>
>         <value>*****</value>
>       </parameter>
>     </ResourceParams>
> 
> 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 Db Test</description>
> <resource-ref>
>    <description>DB Conn</description>
>    <res-ref-name>jdbc/postgres</res-ref-name>
>    <res-type>javax.sql.DataSource</res-type>
>    <res-auth>Container</res-auth>
>    <res-sharing-scope>Sharable</res-sharing-scope> <!--tried adding this, no effect -->
> </resource-ref>
> </web-app>
> 
> I also tried changing my context call from:
> 
> java:/comp/env
> 
> to
> 
> java:comp/env
> 
> with no effect.
> 
> thanks,
> Paul
> 
> Alfonso Martinez wrote:
> 
> > Hi Paul,
> >
> > I am a newbie too, but trying to help. I had a problem like yours recently and found an error in my server.xml. I know you checked that file already, but can you send those (also web.xml) files to me please to see what I can do? Thanks
> >
> > Jose
> >
> > On Fri, Sep 20, 2002 at 11:10:41AM -0500, Paul Salazar wrote:
> > > Hi,
> > >
> > > I am trying to setup a postgresql datasource on tomcat 4.1 with much
> > > frustration.
> > > I have read all the threads out there concerning this matter and I can't
> > > see to
> > > find anyone who has a working example. What I have is this:
> > >
> > > Redhat 7.2 server running:
> > > Postgresql 7.2
> > > Tomcat 4.1
> > >
> > > I have a working Tomcat app that can connect to the Db and perform
> > > queries when manually loading the driver
> > > 'Class.forName("org.postgresql.Driver");
> > > and then doing a getConnection using the URL, Name, Password.
> > >
> > > But when trying to get a connection using a Datasource, as in,
> > >
> > > Context ctx = new InitialContext();
> > > Context envctx = (Context)ctx.lookup("java:/comp/env");
> > > DataSource ds = (DataSource)envctx.lookup("jdbc/postgres"); //jndi name
> > > of the datasource
> > > Connection conn = ds.getConnection();
> > >
> > > the getConnection() statement throws an SQLException: Cannot load JDBC
> > > driver class 'null'
> > >
> > > I have gone over all the server.xml and web.xml files with a fine tooth
> > > comb and assure
> > > you that is not the problem. I have also tried using the jxDBCon drivers
> > > with the same
> > > results. I have come to the conclusion that it must be a tomcat problem.
> > > Has anyone
> > > gotten this to work with this config??
> > >
> > > Paul Salazar
> > >
> >
> > > --
> > > To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> > > For additional commands, e-mail: <ma...@jakarta.apache.org>
> >
> > --
> > To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> > For additional commands, e-mail: <ma...@jakarta.apache.org>
> 

> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Postgresql DataSource Tomcat 4.1 SQLException

Posted by Paul Salazar <pa...@testspectrum.com>.
Alfonso,

Any help is appreciated.
Here they are:

server.xml
----------
    <Resource auth="Container" name="jdbc/postgres" scope="Shareable" type="javax.sql.DataSource"/>
    <ResourceParams name="jdbc/postgres">
      <parameter>
        <name>url</name>
        <value>jdbc:postgresql://roach/testdb</value>
      </parameter>
      <parameter>
        <name>validationQuery</name>
        <value></value>
      </parameter>
      <parameter>
        <name>maxIdle</name>
        <value>10</value>
      </parameter>
      <parameter>
        <name>maxActive</name>
        <value>20</value>
      </parameter>
      <parameter>
        <name>driverClassName</name>
        <value>org.postgresql.Driver</value>
      </parameter>
      <parameter>
        <name>maxWait</name>
        <value>-1</value>
      </parameter>
      <parameter>
        <name>username</name>
        <value>******</value>
      </parameter>
      <parameter>
        <name>factory</name>
        <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
      </parameter>
      <parameter>
        <name>password</name>
        <value>*****</value>
      </parameter>
    </ResourceParams>

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 Db Test</description>
<resource-ref>
   <description>DB Conn</description>
   <res-ref-name>jdbc/postgres</res-ref-name>
   <res-type>javax.sql.DataSource</res-type>
   <res-auth>Container</res-auth>
   <res-sharing-scope>Sharable</res-sharing-scope> <!--tried adding this, no effect -->
</resource-ref>
</web-app>

I also tried changing my context call from:

java:/comp/env

to

java:comp/env

with no effect.

thanks,
Paul

Alfonso Martinez wrote:

> Hi Paul,
>
> I am a newbie too, but trying to help. I had a problem like yours recently and found an error in my server.xml. I know you checked that file already, but can you send those (also web.xml) files to me please to see what I can do? Thanks
>
> Jose
>
> On Fri, Sep 20, 2002 at 11:10:41AM -0500, Paul Salazar wrote:
> > Hi,
> >
> > I am trying to setup a postgresql datasource on tomcat 4.1 with much
> > frustration.
> > I have read all the threads out there concerning this matter and I can't
> > see to
> > find anyone who has a working example. What I have is this:
> >
> > Redhat 7.2 server running:
> > Postgresql 7.2
> > Tomcat 4.1
> >
> > I have a working Tomcat app that can connect to the Db and perform
> > queries when manually loading the driver
> > 'Class.forName("org.postgresql.Driver");
> > and then doing a getConnection using the URL, Name, Password.
> >
> > But when trying to get a connection using a Datasource, as in,
> >
> > Context ctx = new InitialContext();
> > Context envctx = (Context)ctx.lookup("java:/comp/env");
> > DataSource ds = (DataSource)envctx.lookup("jdbc/postgres"); //jndi name
> > of the datasource
> > Connection conn = ds.getConnection();
> >
> > the getConnection() statement throws an SQLException: Cannot load JDBC
> > driver class 'null'
> >
> > I have gone over all the server.xml and web.xml files with a fine tooth
> > comb and assure
> > you that is not the problem. I have also tried using the jxDBCon drivers
> > with the same
> > results. I have come to the conclusion that it must be a tomcat problem.
> > Has anyone
> > gotten this to work with this config??
> >
> > Paul Salazar
> >
>
> > --
> > To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> > For additional commands, e-mail: <ma...@jakarta.apache.org>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Postgresql DataSource Tomcat 4.1 SQLException

Posted by Alex Wallace <to...@rwsoft-online.com>.
I'm using postresql with tomcat usin jndi. If you still have problems tell me
and I'll try to help.

Quoting Ray Madigan <ra...@madigans.org>:

> Paul:
> 
> Did you get this problem fixed.  I have nearly the identical situation
> you
> are using working and will help if you need it.
> 
> Thanks
> 
> -----Original Message-----
> From: Ben Walding [mailto:ben@walding.com]
> Sent: Sunday, September 22, 2002 1:36 AM
> To: Tomcat Users List
> Subject: Re: Postgresql DataSource Tomcat 4.1 SQLException
> 
> 
> The JNDI namespace you want is
> java:comp/env
> 
> and not java:/comp/env
> 
> But I'm not sure if is the cause of the problem.
> 
> 
> 
> 
> Alfonso Martinez wrote:
> 
> >Hi Paul,
> >
> >I am a newbie too, but trying to help. I had a problem like yours
> recently
> and found an error in my server.xml. I know you checked that file
> already,
> but can you send those (also web.xml) files to me please to see what I
> can
> do? Thanks
> >
> >Jose
> >
> >On Fri, Sep 20, 2002 at 11:10:41AM -0500, Paul Salazar wrote:
> >
> >
> >>Hi,
> >>
> >>I am trying to setup a postgresql datasource on tomcat 4.1 with much
> >>frustration.
> >>I have read all the threads out there concerning this matter and I
> can't
> >>see to
> >>find anyone who has a working example. What I have is this:
> >>
> >>Redhat 7.2 server running:
> >>Postgresql 7.2
> >>Tomcat 4.1
> >>
> >>I have a working Tomcat app that can connect to the Db and perform
> >>queries when manually loading the driver
> >>'Class.forName("org.postgresql.Driver");
> >>and then doing a getConnection using the URL, Name, Password.
> >>
> >>But when trying to get a connection using a Datasource, as in,
> >>
> >>Context ctx = new InitialContext();
> >>Context envctx = (Context)ctx.lookup("java:/comp/env");
> >>DataSource ds = (DataSource)envctx.lookup("jdbc/postgres"); //jndi
> name
> >>of the datasource
> >>Connection conn = ds.getConnection();
> >>
> >>the getConnection() statement throws an SQLException: Cannot load
> JDBC
> >>driver class 'null'
> >>
> >>I have gone over all the server.xml and web.xml files with a fine
> tooth
> >>comb and assure
> >>you that is not the problem. I have also tried using the jxDBCon
> drivers
> >>with the same
> >>results. I have come to the conclusion that it must be a tomcat
> problem.
> >>Has anyone
> >>gotten this to work with this config??
> >>
> >>Paul Salazar
> >>
> >>
> >>
> >
> >
> >
> >>--
> >>To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> >>For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >>
> >>
> >
> >--
> >To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> >For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
> >
> >
> >
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 
> 

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Postgresql DataSource Tomcat 4.1 SQLException

Posted by Ray Madigan <ra...@madigans.org>.
Paul:

Did you get this problem fixed.  I have nearly the identical situation you
are using working and will help if you need it.

Thanks

-----Original Message-----
From: Ben Walding [mailto:ben@walding.com]
Sent: Sunday, September 22, 2002 1:36 AM
To: Tomcat Users List
Subject: Re: Postgresql DataSource Tomcat 4.1 SQLException


The JNDI namespace you want is
java:comp/env

and not java:/comp/env

But I'm not sure if is the cause of the problem.




Alfonso Martinez wrote:

>Hi Paul,
>
>I am a newbie too, but trying to help. I had a problem like yours recently
and found an error in my server.xml. I know you checked that file already,
but can you send those (also web.xml) files to me please to see what I can
do? Thanks
>
>Jose
>
>On Fri, Sep 20, 2002 at 11:10:41AM -0500, Paul Salazar wrote:
>
>
>>Hi,
>>
>>I am trying to setup a postgresql datasource on tomcat 4.1 with much
>>frustration.
>>I have read all the threads out there concerning this matter and I can't
>>see to
>>find anyone who has a working example. What I have is this:
>>
>>Redhat 7.2 server running:
>>Postgresql 7.2
>>Tomcat 4.1
>>
>>I have a working Tomcat app that can connect to the Db and perform
>>queries when manually loading the driver
>>'Class.forName("org.postgresql.Driver");
>>and then doing a getConnection using the URL, Name, Password.
>>
>>But when trying to get a connection using a Datasource, as in,
>>
>>Context ctx = new InitialContext();
>>Context envctx = (Context)ctx.lookup("java:/comp/env");
>>DataSource ds = (DataSource)envctx.lookup("jdbc/postgres"); //jndi name
>>of the datasource
>>Connection conn = ds.getConnection();
>>
>>the getConnection() statement throws an SQLException: Cannot load JDBC
>>driver class 'null'
>>
>>I have gone over all the server.xml and web.xml files with a fine tooth
>>comb and assure
>>you that is not the problem. I have also tried using the jxDBCon drivers
>>with the same
>>results. I have come to the conclusion that it must be a tomcat problem.
>>Has anyone
>>gotten this to work with this config??
>>
>>Paul Salazar
>>
>>
>>
>
>
>
>>--
>>To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
>>For additional commands, e-mail:
<ma...@jakarta.apache.org>
>>
>>
>
>--
>To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
>For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>
>
>




--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Postgresql DataSource Tomcat 4.1 SQLException

Posted by Ben Walding <be...@walding.com>.
The JNDI namespace you want is
java:comp/env

and not java:/comp/env

But I'm not sure if is the cause of the problem.




Alfonso Martinez wrote:

>Hi Paul,
>
>I am a newbie too, but trying to help. I had a problem like yours recently and found an error in my server.xml. I know you checked that file already, but can you send those (also web.xml) files to me please to see what I can do? Thanks
>
>Jose 
>
>On Fri, Sep 20, 2002 at 11:10:41AM -0500, Paul Salazar wrote:
>  
>
>>Hi,
>>
>>I am trying to setup a postgresql datasource on tomcat 4.1 with much
>>frustration.
>>I have read all the threads out there concerning this matter and I can't
>>see to
>>find anyone who has a working example. What I have is this:
>>
>>Redhat 7.2 server running:
>>Postgresql 7.2
>>Tomcat 4.1
>>
>>I have a working Tomcat app that can connect to the Db and perform
>>queries when manually loading the driver
>>'Class.forName("org.postgresql.Driver");
>>and then doing a getConnection using the URL, Name, Password.
>>
>>But when trying to get a connection using a Datasource, as in,
>>
>>Context ctx = new InitialContext();
>>Context envctx = (Context)ctx.lookup("java:/comp/env");
>>DataSource ds = (DataSource)envctx.lookup("jdbc/postgres"); //jndi name
>>of the datasource
>>Connection conn = ds.getConnection();
>>
>>the getConnection() statement throws an SQLException: Cannot load JDBC
>>driver class 'null'
>>
>>I have gone over all the server.xml and web.xml files with a fine tooth
>>comb and assure
>>you that is not the problem. I have also tried using the jxDBCon drivers
>>with the same
>>results. I have come to the conclusion that it must be a tomcat problem.
>>Has anyone
>>gotten this to work with this config??
>>
>>Paul Salazar
>>
>>    
>>
>
>  
>
>>--
>>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>>For additional commands, e-mail: <ma...@jakarta.apache.org>
>>    
>>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
>  
>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Postgresql DataSource Tomcat 4.1 SQLException

Posted by Alfonso Martinez <tr...@linuxcenter.com.mx>.
Hi Paul,

I am a newbie too, but trying to help. I had a problem like yours recently and found an error in my server.xml. I know you checked that file already, but can you send those (also web.xml) files to me please to see what I can do? Thanks

Jose 

On Fri, Sep 20, 2002 at 11:10:41AM -0500, Paul Salazar wrote:
> Hi,
> 
> I am trying to setup a postgresql datasource on tomcat 4.1 with much
> frustration.
> I have read all the threads out there concerning this matter and I can't
> see to
> find anyone who has a working example. What I have is this:
> 
> Redhat 7.2 server running:
> Postgresql 7.2
> Tomcat 4.1
> 
> I have a working Tomcat app that can connect to the Db and perform
> queries when manually loading the driver
> 'Class.forName("org.postgresql.Driver");
> and then doing a getConnection using the URL, Name, Password.
> 
> But when trying to get a connection using a Datasource, as in,
> 
> Context ctx = new InitialContext();
> Context envctx = (Context)ctx.lookup("java:/comp/env");
> DataSource ds = (DataSource)envctx.lookup("jdbc/postgres"); //jndi name
> of the datasource
> Connection conn = ds.getConnection();
> 
> the getConnection() statement throws an SQLException: Cannot load JDBC
> driver class 'null'
> 
> I have gone over all the server.xml and web.xml files with a fine tooth
> comb and assure
> you that is not the problem. I have also tried using the jxDBCon drivers
> with the same
> results. I have come to the conclusion that it must be a tomcat problem.
> Has anyone
> gotten this to work with this config??
> 
> Paul Salazar
> 

> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>