Thread: Datasource and tomcat, Postgresql 7.4, jkd1.4.1

Datasource and tomcat, Postgresql 7.4, jkd1.4.1

From
GB Clark
Date:
Hello,

I'm trying to get the jdbc interface working with datasources and just can't seem to
get it.  It works fine with the plain driver.

The error I'm getting is
java.sql.SQLException: Cannot load JDBC driver class 'null'

Here is the stack trace:
java.sql.SQLException: Cannot load JDBC driver class 'null' at
org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:529)at
org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:312)at testme.doGet(Unknown Source) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:740)at
javax.servlet.http.HttpServlet.service(HttpServlet.java:853)at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)at
org.apache.catalina.core.StandardContextValve.invoke!
 (StandardContextValve.java:191) at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)at
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)at
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)at
org.apache.catalina.core!
 .StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.cata
lina.core.ContainerBase.invoke(ContainerBase.java:995) at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)at
org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)at
java.lang.Thread.run(Thread.java:536) 

And here is my code:
Context ctx   = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/postgresql");
Connection connection = ds.getConnection();  <-- This is where it fails.

Here are some .xml things
    <ResourceParams name="jdbc/postgresql">
      <parameter>
        <name>validationQuery</name>
        <value></value>
      </parameter>
      <parameter>
        <name>url</name>
        <value>jdbc:postgresql://prime.vsservices.com:5432/gclarkii</value>
      </parameter>
      <parameter>
        <name>password</name>
        <value></value>
      </parameter>
      <parameter>
        <name>maxActive</name>
        <value>2</value>
      </parameter>
      <parameter>
        <name>maxWait</name>
        <value>5000</value>
      </parameter>
      <parameter>
        <name>driverClassName</name>
        <value>org.postgresql.jdbc2.optional.SimpleDataSource</value>
      </parameter>
      <parameter>
        <name>username</name>
        <value>gclarkii</value>
      </parameter>
      <parameter>
        <name>maxIdle</name>
        <value>6</value>
      </parameter>
    </ResourceParams>

And
<resource-ref>
 <description>postgreSQL Datasource</description>
 <res-ref-name>jdbc/postgresql</res-ref-name>
 <res-type>javax.sql.DataSource</res-type>
 <res-auth>Container</res-auth>
</resource-ref>

I'm fairly new to java but have a good background in C++ and Perl.

Any ideas on where to look?

thanks,

GB






--
GB Clark II             | Roaming FreeBSD Admin
gclarkii@VSServices.COM | General Geek
           CTHULU for President - Why choose the lesser of two evils?

Re: Datasource and tomcat, Postgresql 7.4, jkd1.4.1

From
Vernon Wu
Date:
Have you check the driver to see whether it is in your class path? You can have the driver in several places

<your-app>/WEB-INF/lib
<TC>/common/lib

Either location is a good place to have the tar ball.


10/02/2003 5:00:12 PM, GB Clark <postgres@vsservices.com> wrote:

>Hello,
>
>I'm trying to get the jdbc interface working with datasources and just can't seem to
>get it.  It works fine with the plain driver.
>
>The error I'm getting is
>java.sql.SQLException: Cannot load JDBC driver class 'null'
>
>Here is the stack trace:
>java.sql.SQLException: Cannot load JDBC driver class 'null' at
org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:529) at
org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:312) at testme.doGet(Unknown
Source) at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at javax.servlet.http.HttpServlet.service
(HttpServlet.java:853) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
(ApplicationFilterChain.java:247) at org.apache.catalina.core.ApplicationFilterChain.doFilter
(ApplicationFilterChain.java:193) at org.apache.catalina.core.StandardWrapperValve.invoke
(StandardWrapperValve.java:260) at org.apache.catalina.core.StandardPipeline
$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at
org.apache.catalina.core.StandardContextValve.invoke!
> (StandardContextValve.java:191) at org.apache.catalina.core.StandardPipeline
$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415) at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180) at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170) at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172) at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) at
org.apache.catalina.core!
> .StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.cata
>lina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardEngineValve.invoke
(StandardEngineValve.java:174) at org.apache.catalina.core.StandardPipeline
$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at
org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223) at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432) at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386) at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534) at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530) at java.lang.Thread.run
(Thread.java:536)
>
>And here is my code:
>Context ctx   = new InitialContext();
>DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/postgresql");
>Connection connection = ds.getConnection();  <-- This is where it fails.
>
>Here are some .xml things
>    <ResourceParams name="jdbc/postgresql">
>      <parameter>
>        <name>validationQuery</name>
>        <value></value>
>      </parameter>
>      <parameter>
>        <name>url</name>
>        <value>jdbc:postgresql://prime.vsservices.com:5432/gclarkii</value>
>      </parameter>
>      <parameter>
>        <name>password</name>
>        <value></value>
>      </parameter>
>      <parameter>
>        <name>maxActive</name>
>        <value>2</value>
>      </parameter>
>      <parameter>
>        <name>maxWait</name>
>        <value>5000</value>
>      </parameter>
>      <parameter>
>        <name>driverClassName</name>
>        <value>org.postgresql.jdbc2.optional.SimpleDataSource</value>
>      </parameter>
>      <parameter>
>        <name>username</name>
>        <value>gclarkii</value>
>      </parameter>
>      <parameter>
>        <name>maxIdle</name>
>        <value>6</value>
>      </parameter>
>    </ResourceParams>
>
>And
><resource-ref>
> <description>postgreSQL Datasource</description>
> <res-ref-name>jdbc/postgresql</res-ref-name>
> <res-type>javax.sql.DataSource</res-type>
> <res-auth>Container</res-auth>
></resource-ref>
>
>I'm fairly new to java but have a good background in C++ and Perl.
>
>Any ideas on where to look?
>
>thanks,
>
>GB
>
>
>
>
>
>
>--
>GB Clark II             | Roaming FreeBSD Admin
>gclarkii@VSServices.COM | General Geek
>           CTHULU for President - Why choose the lesser of two evils?
>
>---------------------------(end of broadcast)---------------------------
>TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>




Re: Datasource and tomcat, Postgresql 7.4, jkd1.4.1 --

From
GB Clark
Date:
On Mon, 10 Feb 2003 20:25:14 -0800
Vernon Wu <vernonw@gatewaytech.com> wrote:

>
> Have you check the driver to see whether it is in your class path? You can have the driver in several places
>
> <your-app>/WEB-INF/lib
> <TC>/common/lib
>
> Either location is a good place to have the tar ball.

I would think that the system would die somewhere with a class not found instead of the can not load
'null' class, but I don't know.

At the bottom I've included more stuff.

>
> 10/02/2003 5:00:12 PM, GB Clark <postgres@vsservices.com> wrote:
>
> >Hello,
> >
> >I'm trying to get the jdbc interface working with datasources and just can't seem to
> >get it.  It works fine with the plain driver.
> >
> >The error I'm getting is
> >java.sql.SQLException: Cannot load JDBC driver class 'null'
> >
> >Here is the stack trace:
> >java.sql.SQLException: Cannot load JDBC driver class 'null' at
> org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:529) at
> org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:312) at testme.doGet(Unknown
> Source) at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at javax.servlet.http.HttpServlet.service
> (HttpServlet.java:853) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter
> (ApplicationFilterChain.java:247) at org.apache.catalina.core.ApplicationFilterChain.doFilter
> (ApplicationFilterChain.java:193) at org.apache.catalina.core.StandardWrapperValve.invoke
> (StandardWrapperValve.java:260) at org.apache.catalina.core.StandardPipeline
> $StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at
> org.apache.catalina.core.StandardContextValve.invoke!
> > (StandardContextValve.java:191) at org.apache.catalina.core.StandardPipeline
> $StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at
> org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415) at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180) at
> org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at
> org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170) at
> org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172) at
> org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641) at
> org.apache.catalina.core!
> > .StandardPipeline.invoke(StandardPipeline.java:480) at org.apache.cata
> >lina.core.ContainerBase.invoke(ContainerBase.java:995) at org.apache.catalina.core.StandardEngineValve.invoke
> (StandardEngineValve.java:174) at org.apache.catalina.core.StandardPipeline
> $StandardPipelineValveContext.invokeNext(StandardPipeline.java:643) at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480) at
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995) at
> org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223) at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432) at
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386) at
> org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534) at
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530) at java.lang.Thread.run
> (Thread.java:536)
> >
> >And here is my code:
> >Context ctx   = new InitialContext();
> >DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/postgresql");
> >Connection connection = ds.getConnection();  <-- This is where it fails.
> >
> >Here are some .xml things
> >    <ResourceParams name="jdbc/postgresql">
> >      <parameter>
> >        <name>validationQuery</name>
> >        <value></value>
> >      </parameter>
> >      <parameter>
> >        <name>url</name>
> >        <value>jdbc:postgresql://prime.vsservices.com:5432/gclarkii</value>
> >      </parameter>
> >      <parameter>
> >        <name>password</name>
> >        <value></value>
> >      </parameter>
> >      <parameter>
> >        <name>maxActive</name>
> >        <value>2</value>
> >      </parameter>
> >      <parameter>
> >        <name>maxWait</name>
> >        <value>5000</value>
> >      </parameter>
> >      <parameter>
> >        <name>driverClassName</name>
> >        <value>org.postgresql.jdbc2.optional.SimpleDataSource</value>

I've changed this back to org.postgresql.Driver.  At this point I'm down to trying anything...

> >      </parameter>
> >      <parameter>
> >        <name>username</name>
> >        <value>gclarkii</value>
> >      </parameter>
> >      <parameter>
> >        <name>maxIdle</name>
> >        <value>6</value>
> >      </parameter>
> >    </ResourceParams>
> >
> >And
> ><resource-ref>
> > <description>postgreSQL Datasource</description>
> > <res-ref-name>jdbc/postgresql</res-ref-name>
> > <res-type>javax.sql.DataSource</res-type>
> > <res-auth>Container</res-auth>
> ></resource-ref>
> >
> >I'm fairly new to java but have a good background in C++ and Perl.
> >
> >Any ideas on where to look?
> >
> >thanks,
> >
> >GB

Well postgresql.jar (I've tried both the downloaded one and compiling one) is in TC/common/lib and
nowhere else (I do a classpath for my compiles).  Hummm... I also seem to be getting this error
when the servlet is loaded/reloaded:
2003-02-11 08:54:41 NamingContextListener[/Standalone/localhost/testme]: Failed to bind object:
javax.naming.NamingException:Name postgresql is already bound in this Context 

Arrrggghhhhhh

Thanks for the help.

GB

--
GB Clark II             | Roaming FreeBSD Admin
gclarkii@VSServices.COM | General Geek
           CTHULU for President - Why choose the lesser of two evils?

Re: Datasource and tomcat, Postgresql 7.4, jkd1.4.1 --

From
GB Clark
Date:
Hello,

Well I got my problem solved by searching through the tomcat mailling lists...

I had to include my database parameters INSIDE the context for my application.  Can anyone tell
me why this fixed my problem?  Or is that where the database parameters should be anyway...

If I wanted another servlet to use the same datasource would I have to duplicate the parameters
everytime?

Something does not seem right there...

Thanks for all the help.

GB

--
GB Clark II             | Roaming FreeBSD Admin
gclarkii@VSServices.COM | General Geek
           CTHULU for President - Why choose the lesser of two evils?

Re: Datasource and tomcat, Postgresql 7.4, jkd1.4.1 --

From
Dave Cramer
Date:
Servlet containers have very specific rules on object visibility

it depends on where you put the jar. if you put the jar in the context,
then the class won't even exist outside of the context.

when you say servlet, is this a servlet inside the context or out?

FWIW I gave up on tomcat in favour of jetty. No automatic class
reloading, but that's where tomcat gets complicated.

Dave

On Tue, 2003-02-11 at 22:12, GB Clark wrote:
> Hello,
>
> Well I got my problem solved by searching through the tomcat mailling lists...
>
> I had to include my database parameters INSIDE the context for my application.  Can anyone tell
> me why this fixed my problem?  Or is that where the database parameters should be anyway...
>
> If I wanted another servlet to use the same datasource would I have to duplicate the parameters
> everytime?
>
> Something does not seem right there...
>
> Thanks for all the help.
>
> GB
--
Dave Cramer <Dave@micro-automation.net>


Re: Datasource and tomcat, Postgresql 7.4, jkd1.4.1 --

From
Christopher Elkins
Date:
This is off-topic, but it's not exactly well-documented anywhere.


On Tuesday, February 11, 2003, at 07:12 PM, GB Clark wrote:

> I had to include my database parameters INSIDE the context for my
> application.  Can anyone tell
> me why this fixed my problem?  Or is that where the database
> parameters should be anyway...

Typically, that's where they're defined. However, as you've noticed,
this is less than ideal for resources that you want to share across
webapp contexts.

> If I wanted another servlet to use the same datasource would I have to
> duplicate the parameters
> everytime?

You can configure global resources (i.e., in the
<GlobalNamingResources> section), but you need to use a slightly
different syntax in your webapp context in order for it to "see" them.

Specifically, add the relevant <Resource> and <ResourceParams> elements
to the global resources section. Then, in your webapp context add a
<ResourceLink> element.

For example,

<GlobalNamingResources>
   <Resource name="jdbc/ globaldb" type="javax.sql.DataSource" />
   <ResourceParams name="jdbc/ globaldb">
     .. the usual DBCP configuration stuff ...
   </ResourceParams>
</GlobalNamingResources>
...
<Context path="/myapp">
   <ResourceLink name="jdbc/mydb" global="jdbc/globaldb"
type="javax.sql.DataSource" />
</Context>

Your code can now lookup "java:comp/env/jdbc/mydb" and get a reference
to the globally-defined data source. Keep in mind that because this is
a Tomcat-specific configuration feature, you cannot define it in the
webapp's deployment descriptor (i.e., web.xml) and must therefore
deploy your webapp "manually" (e.g., through Tomcat's manager
application).

--
Christopher Elkins


Re: Datasource and tomcat, Postgresql 7.4, jkd1.4.1 --

From
Tony Grant
Date:
On Tue, 2003-02-11 at 09:56, GB Clark wrote:

> > >The error I'm getting is
> > >java.sql.SQLException: Cannot load JDBC driver class 'null'

> > >And here is my code:
> > >Context ctx   = new InitialContext();

How about

Driver DriverName = (Driver)Class.forName("org.postgresql.Driver").newInstance();
Connection connection = ds.getConnection("jdbc:postgresql://x.x.x.x:5432/dbname);  <-- This is where it fails.

Cheers

Tony Grant
--
www.tgds.net Library management software toolkit,
redhat linux on Sony Vaio C1XD,
Dreamweaver MX with Tomcat and PostgreSQL