Datasource and tomcat, Postgresql 7.4, jkd1.4.1

Поиск
Список
Период
Сортировка
Искать

Datasource and tomcat, Postgresql 7.4, jkd1.4.1

От:
GB Clark <postgres@vsservices.com>
Дата:
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
    
      
        validationQuery
        
      
      
        url
        jdbc:postgresql://prime.vsservices.com:5432/gclarkii
      
      
        password
        
      
      
        maxActive
        2
      
      
        maxWait
        5000
      
      
        driverClassName
        org.postgresql.jdbc2.optional.SimpleDataSource
      
      
        username
        gclarkii
      
      
        maxIdle
        6
      
    

And

 postgreSQL Datasource
 jdbc/postgresql
 javax.sql.DataSource
 Container


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

От:
Vernon Wu <vernonw@gatewaytech.com>
Дата:

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

/WEB-INF/lib
/common/lib

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


10/02/2003 5:00:12 PM, GB Clark  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
>    
>      
>        validationQuery
>        
>      
>      
>        url
>        jdbc:postgresql://prime.vsservices.com:5432/gclarkii
>      
>      
>        password
>        
>      
>      
>        maxActive
>        2
>      
>      
>        maxWait
>        5000
>      
>      
>        driverClassName
>        org.postgresql.jdbc2.optional.SimpleDataSource
>      
>      
>        username
>        gclarkii
>      
>      
>        maxIdle
>        6
>      
>    
>
>And
>
> postgreSQL Datasource
> jdbc/postgresql
> javax.sql.DataSource
> Container
>
>
>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 --

От:
GB Clark <postgres@vsservices.com>
Дата:
On Mon, 10 Feb 2003 20:25:14 -0800
Vernon Wu  wrote:

> 
> Have you check the driver to see whether it is in your class path? You can have the driver in several places
> 
> /WEB-INF/lib
> /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  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
> >    
> >      
> >        validationQuery
> >        
> >      
> >      
> >        url
> >        jdbc:postgresql://prime.vsservices.com:5432/gclarkii
> >      
> >      
> >        password
> >        
> >      
> >      
> >        maxActive
> >        2
> >      
> >      
> >        maxWait
> >        5000
> >      
> >      
> >        driverClassName
> >        org.postgresql.jdbc2.optional.SimpleDataSource

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

> >      
> >      
> >        username
> >        gclarkii
> >      
> >      
> >        maxIdle
> >        6
> >      
> >    
> >
> >And
> >
> > postgreSQL Datasource
> > jdbc/postgresql
> > javax.sql.DataSource
> > Container
> >
> >
> >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 --

От:
GB Clark <postgres@vsservices.com>
Дата:
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 --

От:
Dave Cramer <Dave@micro-automation.net>
Дата:
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 

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

От:
Christopher Elkins <chrise@scardini.com>
Дата:
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 
 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  and  elements 
to the global resources section. Then, in your webapp context add a 
 element.

For example,


   
   
     .. the usual DBCP configuration stuff ...
   

...

   


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 --

От:
Tony Grant <tgrant@tgds.net>
Дата:
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

FAQ