You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mark Slater <li...@humanesoftware.com> on 2006/04/04 21:09:09 UTC
PostgreSQL access via JNDI
I've been trying to get PostgreSQL set up to be accessed through JNDI
in Tomcat 5.5.x. I found the docs page describing it, "jndi-
datasource-examples-howto.html", and followed the example there, but
it still doesn't work. I'm trying to provide access to PostgreSQL for
use by both JDO and JCR in my web-apps.
Here's the Resource definition I'm using:
<Resource name="jdbc/whisper_db"
auth="Container"
type="javax.sql.Datasource"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://127.0.0.1:5432/my_db"
username="-------------------"
password="-------------------""
maxActive="10"
maxIdle="100"
maxWait="3000" />
In my application's META-INF/context.xml, I have the following
ResourceLink:
<ResourceLink
global="jdbc/whisper_db" name="jdbc/whisper_orm"
type="javax.sql.Datasource" />
In my application's WEB-INF/web.xml, I have the following resource-
env-ref:
<resource-env-ref>
<description>Whisper's Database</description>
<resource-env-ref-name>jdbc/whisper_orm</resource-env-ref-name>
<resource-env-ref-type>javax.sql.Datasource</resource-env-
ref-type>
</resource-env-ref>
Depending on where I put the Resource definition, I get different
errors.
If I put it in the web-app's META-INF/context.xml, or in $TOMCAT_HOME/
conf/context.xml, my JDO implementation complains:
NestableRuntimeException: There was an error duing JNDI lookup
of the name "java:comp/env/jdbc/whisper_orm".
....
Caused by: javax.naming.NameNotFoundException: Name jdbc is not
bound in this Context
If I put it in $TOMCAT_HOME/conf/server.xml, in the
GlobalNamingResources section, I get:
2006-04-04 11:58:27,866 ERROR
[org.apache.catalina.mbeans.GlobalResourcesLifecycleListener] -
<Exception processing Global JNDI Resources>
javax.naming.NamingException: Cannot create resource instance
at
org.apache.naming.factory.ResourceFactory.getObjectInstance
(ResourceFactory.java:132)
at javax.naming.spi.NamingManager.getObjectInstance
(NamingManager.java:304)
at org.apache.naming.NamingContext.lookup(NamingContext.java:
792)
at org.apache.naming.NamingContext.lookup(NamingContext.java:
152)
at
org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans
(GlobalResourcesLifecycleListener.java:138)
at
org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans
(GlobalResourcesLifecycleListener.java:143)
at
org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans
(GlobalResourcesLifecycleListener.java:108)
at
org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.lifecycleEve
nt(GlobalResourcesLifecycleListener.java:80)
at
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent
(LifecycleSupport.java:119)
at org.apache.catalina.core.StandardServer.start
(StandardServer.java:693)
at org.apache.catalina.startup.Catalina.start(Catalina.java:
551)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start
(Bootstrap.java:275)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:
413)
I'm assuming these errors are related, and that whatever is causing
the NamingException is the same fundamental problem causing the
NameNotFoundException in the context-based configuration. My problem
is that I can't figure out what it is. The driver for the database
(postgresql-8.1-405.jdbc3.jar) is in $TOMCAT_HOME/common/lib/, and
I've also tried adding commons-dbcp-1.2.1.jar and commons-
pool-1.2.jar alongside it (even though the docs say that shouldn't be
necessary), but get the same errors.
Is there any logging that I can turn on that will tell me the WHY
Tomcat "Cannot create resource instance"? Or am I doing something
obviously stupid with my Resource definition? Or could it be
something else entirely?
Any suggestions would be really helpful.
Thanks!
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: PostgreSQL access via JNDI
Posted by Mark Slater <li...@humanesoftware.com>.
My mis-capitalization of DataSource was the main problem. Also, I was
trying to use Resource and ResourceLink in META-INF/context.xml;
ResourceLink is apparently not needed if the Resource is local to the
webapp.
Thank you both for your help!
Mark
On Apr 5, 2006, at 5:11 AM, Hadraba Petr wrote:
> Hi,
>
> I'm successfuly using PostgreSQL 8.1.3 with Tomcat 5.5.15 with JDBC
> drivers 405 (build)...
>
> I have the <Resource ... /> definition in the META-INF/context.xml and
> in the WEB-INF/web.xml I have the <resource-ref/> element. The
> <resource-env-ref/> I'm using for the ActiveMQ client connection.
>
> Also the JDBC drivers are placed in the common/lib directory.
>
> If you search the list, you will find my previous posts containing all
> the configuration files.
>
> Have a lot of fun!
>
> PETR
>
>
> On 4/5/06, Amila Suriarachchi <am...@gmail.com> wrote:
>> On 4/5/06, Mark Slater <li...@humanesoftware.com> wrote:
>>>>
>>>> I've been trying to get PostgreSQL set up to be accessed through
>>>> JNDI
>>>> in Tomcat 5.5.x. I found the docs page describing it, "jndi-
>>>> datasource-examples-howto.html", and followed the example there,
>>>> but
>>>> it still doesn't work. I'm trying to provide access to
>>>> PostgreSQL for
>>>> use by both JDO and JCR in my web-apps.
>>>>
>>>> Here's the Resource definition I'm using:
>>>>
>>>> <Resource name="jdbc/whisper_db"
>>>> auth="Container"
>>>> type="javax.sql.Datasource "
>>>
>>>
>> S should be capital as well DataSource
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: PostgreSQL access via JNDI
Posted by Hadraba Petr <ha...@bluetone.cz>.
Hi,
I'm successfuly using PostgreSQL 8.1.3 with Tomcat 5.5.15 with JDBC
drivers 405 (build)...
I have the <Resource ... /> definition in the META-INF/context.xml and
in the WEB-INF/web.xml I have the <resource-ref/> element. The
<resource-env-ref/> I'm using for the ActiveMQ client connection.
Also the JDBC drivers are placed in the common/lib directory.
If you search the list, you will find my previous posts containing all
the configuration files.
Have a lot of fun!
PETR
On 4/5/06, Amila Suriarachchi <am...@gmail.com> wrote:
> On 4/5/06, Mark Slater <li...@humanesoftware.com> wrote:
> > >
> > > I've been trying to get PostgreSQL set up to be accessed through JNDI
> > > in Tomcat 5.5.x. I found the docs page describing it, "jndi-
> > > datasource-examples-howto.html", and followed the example there, but
> > > it still doesn't work. I'm trying to provide access to PostgreSQL for
> > > use by both JDO and JCR in my web-apps.
> > >
> > > Here's the Resource definition I'm using:
> > >
> > > <Resource name="jdbc/whisper_db"
> > > auth="Container"
> > > type="javax.sql.Datasource "
> >
> >
> S should be capital as well DataSource
>
> driverClassName="org.postgresql.Driver"
> > > url="jdbc:postgresql://127.0.0.1:5432/my_db"
> >
> >
> > this is a postgres problem rather than tomcat problem.
> > try here jdbc:postgresql://localhost:5432/my_db (or template1)
> >
> > if you want to access the database giving 127.0.0.1 you have to put
> > an entry in pg_hda.conf file.
> >
> >
> >
> > username="-------------------"
> > > password="-------------------""
> > > maxActive="10"
> > > maxIdle="100"
> > > maxWait="3000" />
> > >
> > >
> > > In my application's META-INF/context.xml, I have the following
> > > ResourceLink:
> > >
> > > <ResourceLink
> > > global="jdbc/whisper_db" name="jdbc/whisper_orm"
> > > type="javax.sql.Datasource " />
> > >
> > > In my application's WEB-INF/web.xml, I have the following resource-
> > > env-ref:
> > >
> > > <resource-env-ref>
> > > <description>Whisper's Database</description>
> > > <resource-env-ref-name>jdbc/whisper_orm</resource-env-ref-name>
> > >
> > > <resource-env-ref-type>javax.sql.Datasource</resource-env-
> > > ref-type>
> > > </resource-env-ref>
> > >
> > >
> > > Depending on where I put the Resource definition, I get different
> > > errors.
> > >
> > > If I put it in the web-app's META-INF/context.xml, or in $TOMCAT_HOME/
> > > conf/context.xml, my JDO implementation complains:
> > > NestableRuntimeException: There was an error duing JNDI lookup
> > > of the name "java:comp/env/jdbc/whisper_orm".
> > > ....
> > > Caused by: javax.naming.NameNotFoundException: Name jdbc is not
> > > bound in this Context
> > >
> > > If I put it in $TOMCAT_HOME/conf/server.xml, in the
> > > GlobalNamingResources section, I get:
> > >
> > > 2006-04-04 11:58:27,866 ERROR
> > > [org.apache.catalina.mbeans.GlobalResourcesLifecycleListener] -
> > > <Exception processing Global JNDI Resources>
> > > javax.naming.NamingException: Cannot create resource instance
> > > at
> > > org.apache.naming.factory.ResourceFactory.getObjectInstance
> > > (ResourceFactory.java:132)
> > > at javax.naming.spi.NamingManager.getObjectInstance
> > > (NamingManager.java:304)
> > > at org.apache.naming.NamingContext.lookup(NamingContext.java:
> > > 792)
> > > at org.apache.naming.NamingContext.lookup (NamingContext.java:
> > > 152)
> > > at
> > > org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans
> > > (GlobalResourcesLifecycleListener.java:138)
> > > at
> > > org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans
> > > (GlobalResourcesLifecycleListener.java:143)
> > > at
> > > org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans
> > > (GlobalResourcesLifecycleListener.java:108)
> > > at
> > > org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.lifecycleEve
> > > nt(GlobalResourcesLifecycleListener.java:80)
> > > at
> > > org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent
> > > (LifecycleSupport.java:119)
> > > at org.apache.catalina.core.StandardServer.start
> > > (StandardServer.java:693)
> > > at org.apache.catalina.startup.Catalina.start(Catalina.java:
> > > 551)
> > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > > at sun.reflect.NativeMethodAccessorImpl.invoke
> > > (NativeMethodAccessorImpl.java:39)
> > > at sun.reflect.DelegatingMethodAccessorImpl.invoke
> > > (DelegatingMethodAccessorImpl.java:25)
> > > at java.lang.reflect.Method.invoke(Method.java:585)
> > > at org.apache.catalina.startup.Bootstrap.start
> > > (Bootstrap.java:275)
> > > at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:
> > > 413)
> > >
> > > I'm assuming these errors are related, and that whatever is causing
> > > the NamingException is the same fundamental problem causing the
> > > NameNotFoundException in the context-based configuration. My problem
> > > is that I can't figure out what it is. The driver for the database
> > > (postgresql-8.1-405.jdbc3.jar ) is in $TOMCAT_HOME/common/lib/, and
> > > I've also tried adding commons-dbcp-1.2.1.jar and commons-
> > > pool-1.2.jar alongside it (even though the docs say that shouldn't be
> > > necessary), but get the same errors.
> > >
> > > Is there any logging that I can turn on that will tell me the WHY
> > > Tomcat "Cannot create resource instance"? Or am I doing something
> > > obviously stupid with my Resource definition? Or could it be
> > > something else entirely?
> > >
> > > Any suggestions would be really helpful.
> > >
> > > Thanks!
> > >
> > > Mark
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > > For additional commands, e-mail: users-help@tomcat.apache.org
> > >
> > >
> >
>
>
--
Petr Hadraba
graphic artist and software designer
http://people.hadraba-soft.com/~petr
hadrabap@bluetone.cz
Re: PostgreSQL access via JNDI
Posted by Amila Suriarachchi <am...@gmail.com>.
On 4/5/06, Mark Slater <li...@humanesoftware.com> wrote:
> >
> > I've been trying to get PostgreSQL set up to be accessed through JNDI
> > in Tomcat 5.5.x. I found the docs page describing it, "jndi-
> > datasource-examples-howto.html", and followed the example there, but
> > it still doesn't work. I'm trying to provide access to PostgreSQL for
> > use by both JDO and JCR in my web-apps.
> >
> > Here's the Resource definition I'm using:
> >
> > <Resource name="jdbc/whisper_db"
> > auth="Container"
> > type="javax.sql.Datasource "
>
>
S should be capital as well DataSource
driverClassName="org.postgresql.Driver"
> > url="jdbc:postgresql://127.0.0.1:5432/my_db"
>
>
> this is a postgres problem rather than tomcat problem.
> try here jdbc:postgresql://localhost:5432/my_db (or template1)
>
> if you want to access the database giving 127.0.0.1 you have to put
> an entry in pg_hda.conf file.
>
>
>
> username="-------------------"
> > password="-------------------""
> > maxActive="10"
> > maxIdle="100"
> > maxWait="3000" />
> >
> >
> > In my application's META-INF/context.xml, I have the following
> > ResourceLink:
> >
> > <ResourceLink
> > global="jdbc/whisper_db" name="jdbc/whisper_orm"
> > type="javax.sql.Datasource " />
> >
> > In my application's WEB-INF/web.xml, I have the following resource-
> > env-ref:
> >
> > <resource-env-ref>
> > <description>Whisper's Database</description>
> > <resource-env-ref-name>jdbc/whisper_orm</resource-env-ref-name>
> >
> > <resource-env-ref-type>javax.sql.Datasource</resource-env-
> > ref-type>
> > </resource-env-ref>
> >
> >
> > Depending on where I put the Resource definition, I get different
> > errors.
> >
> > If I put it in the web-app's META-INF/context.xml, or in $TOMCAT_HOME/
> > conf/context.xml, my JDO implementation complains:
> > NestableRuntimeException: There was an error duing JNDI lookup
> > of the name "java:comp/env/jdbc/whisper_orm".
> > ....
> > Caused by: javax.naming.NameNotFoundException: Name jdbc is not
> > bound in this Context
> >
> > If I put it in $TOMCAT_HOME/conf/server.xml, in the
> > GlobalNamingResources section, I get:
> >
> > 2006-04-04 11:58:27,866 ERROR
> > [org.apache.catalina.mbeans.GlobalResourcesLifecycleListener] -
> > <Exception processing Global JNDI Resources>
> > javax.naming.NamingException: Cannot create resource instance
> > at
> > org.apache.naming.factory.ResourceFactory.getObjectInstance
> > (ResourceFactory.java:132)
> > at javax.naming.spi.NamingManager.getObjectInstance
> > (NamingManager.java:304)
> > at org.apache.naming.NamingContext.lookup(NamingContext.java:
> > 792)
> > at org.apache.naming.NamingContext.lookup (NamingContext.java:
> > 152)
> > at
> > org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans
> > (GlobalResourcesLifecycleListener.java:138)
> > at
> > org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans
> > (GlobalResourcesLifecycleListener.java:143)
> > at
> > org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans
> > (GlobalResourcesLifecycleListener.java:108)
> > at
> > org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.lifecycleEve
> > nt(GlobalResourcesLifecycleListener.java:80)
> > at
> > org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent
> > (LifecycleSupport.java:119)
> > at org.apache.catalina.core.StandardServer.start
> > (StandardServer.java:693)
> > at org.apache.catalina.startup.Catalina.start(Catalina.java:
> > 551)
> > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> > at sun.reflect.NativeMethodAccessorImpl.invoke
> > (NativeMethodAccessorImpl.java:39)
> > at sun.reflect.DelegatingMethodAccessorImpl.invoke
> > (DelegatingMethodAccessorImpl.java:25)
> > at java.lang.reflect.Method.invoke(Method.java:585)
> > at org.apache.catalina.startup.Bootstrap.start
> > (Bootstrap.java:275)
> > at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:
> > 413)
> >
> > I'm assuming these errors are related, and that whatever is causing
> > the NamingException is the same fundamental problem causing the
> > NameNotFoundException in the context-based configuration. My problem
> > is that I can't figure out what it is. The driver for the database
> > (postgresql-8.1-405.jdbc3.jar ) is in $TOMCAT_HOME/common/lib/, and
> > I've also tried adding commons-dbcp-1.2.1.jar and commons-
> > pool-1.2.jar alongside it (even though the docs say that shouldn't be
> > necessary), but get the same errors.
> >
> > Is there any logging that I can turn on that will tell me the WHY
> > Tomcat "Cannot create resource instance"? Or am I doing something
> > obviously stupid with my Resource definition? Or could it be
> > something else entirely?
> >
> > Any suggestions would be really helpful.
> >
> > Thanks!
> >
> > Mark
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >
> >
>
Re: PostgreSQL access via JNDI
Posted by Amila Suriarachchi <am...@gmail.com>.
On 4/5/06, Mark Slater <li...@humanesoftware.com> wrote:
>
> I've been trying to get PostgreSQL set up to be accessed through JNDI
> in Tomcat 5.5.x. I found the docs page describing it, "jndi-
> datasource-examples-howto.html", and followed the example there, but
> it still doesn't work. I'm trying to provide access to PostgreSQL for
> use by both JDO and JCR in my web-apps.
>
> Here's the Resource definition I'm using:
>
> <Resource name="jdbc/whisper_db"
> auth="Container"
> type="javax.sql.Datasource"
> driverClassName="org.postgresql.Driver"
> url="jdbc:postgresql://127.0.0.1:5432/my_db"
this is a postgres problem rather than tomcat problem.
try here jdbc:postgresql://localhost:5432/my_db (or template1)
if you want to access the database giving 127.0.0.1 you have to put
an entry in pg_hda.conf file.
username="-------------------"
> password="-------------------""
> maxActive="10"
> maxIdle="100"
> maxWait="3000" />
>
>
> In my application's META-INF/context.xml, I have the following
> ResourceLink:
>
> <ResourceLink
> global="jdbc/whisper_db" name="jdbc/whisper_orm"
> type="javax.sql.Datasource" />
>
> In my application's WEB-INF/web.xml, I have the following resource-
> env-ref:
>
> <resource-env-ref>
> <description>Whisper's Database</description>
> <resource-env-ref-name>jdbc/whisper_orm</resource-env-ref-name>
> <resource-env-ref-type>javax.sql.Datasource</resource-env-
> ref-type>
> </resource-env-ref>
>
>
> Depending on where I put the Resource definition, I get different
> errors.
>
> If I put it in the web-app's META-INF/context.xml, or in $TOMCAT_HOME/
> conf/context.xml, my JDO implementation complains:
> NestableRuntimeException: There was an error duing JNDI lookup
> of the name "java:comp/env/jdbc/whisper_orm".
> ....
> Caused by: javax.naming.NameNotFoundException: Name jdbc is not
> bound in this Context
>
> If I put it in $TOMCAT_HOME/conf/server.xml, in the
> GlobalNamingResources section, I get:
>
> 2006-04-04 11:58:27,866 ERROR
> [org.apache.catalina.mbeans.GlobalResourcesLifecycleListener] -
> <Exception processing Global JNDI Resources>
> javax.naming.NamingException: Cannot create resource instance
> at
> org.apache.naming.factory.ResourceFactory.getObjectInstance
> (ResourceFactory.java:132)
> at javax.naming.spi.NamingManager.getObjectInstance
> (NamingManager.java:304)
> at org.apache.naming.NamingContext.lookup(NamingContext.java:
> 792)
> at org.apache.naming.NamingContext.lookup(NamingContext.java:
> 152)
> at
> org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans
> (GlobalResourcesLifecycleListener.java:138)
> at
> org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans
> (GlobalResourcesLifecycleListener.java:143)
> at
> org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans
> (GlobalResourcesLifecycleListener.java:108)
> at
> org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.lifecycleEve
> nt(GlobalResourcesLifecycleListener.java:80)
> at
> org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent
> (LifecycleSupport.java:119)
> at org.apache.catalina.core.StandardServer.start
> (StandardServer.java:693)
> at org.apache.catalina.startup.Catalina.start(Catalina.java:
> 551)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke
> (NativeMethodAccessorImpl.java:39)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke
> (DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:585)
> at org.apache.catalina.startup.Bootstrap.start
> (Bootstrap.java:275)
> at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:
> 413)
>
> I'm assuming these errors are related, and that whatever is causing
> the NamingException is the same fundamental problem causing the
> NameNotFoundException in the context-based configuration. My problem
> is that I can't figure out what it is. The driver for the database
> (postgresql-8.1-405.jdbc3.jar) is in $TOMCAT_HOME/common/lib/, and
> I've also tried adding commons-dbcp-1.2.1.jar and commons-
> pool-1.2.jar alongside it (even though the docs say that shouldn't be
> necessary), but get the same errors.
>
> Is there any logging that I can turn on that will tell me the WHY
> Tomcat "Cannot create resource instance"? Or am I doing something
> obviously stupid with my Resource definition? Or could it be
> something else entirely?
>
> Any suggestions would be really helpful.
>
> Thanks!
>
> Mark
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>