You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Dan Eriksson <Da...@springmobil.se> on 2008/04/10 04:15:08 UTC

tomcat not able to connect to postgresql?

Hi list!

I am trying to configure apache + tomcat using mod_jk on different machines with virtual hosts, i.e one frontend running apache (2.2.3-4+etch4), one backend running tomcat 6 (binary apache-tomcat-6.0.16) with postgresql (postgresql-8.1, 8.1.11-0etch1) on debian etch.

My virtual host is called myapp.mydomain.com.

The problem is that when I am using context in my virtual host config for tomcat I receive the following in my logfile, catalina.out,

javax.naming.NamingException: Cannot create resource instance
        at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:143)
        at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:793)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
        at se.springmobil.groupadmin.servlets.ControlServlet.init(ControlServlet.java:86)
        at javax.servlet.GenericServlet.init(GenericServlet.java:212)
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
        at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
        at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4364)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
        at org.apache.catalina.core.StandardService.start(StandardService.java:516)
        at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
        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:597)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
        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:597)
        at org.apache.commons.daemon.support.DaemonLoader.start(DaemonLoader.java:177)
ContextListener: attributeAdded('com.sun.faces.ApplicationAssociate', 'com.sun.faces.application.ApplicationAssociate@ecb67f')

If I try to connect to my vhost now everything looks ok, no errors anywhere, but when I try to login I get a message that the database is not online and in my logfile I see this:

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect UR
L 'null'
        at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1150)
        at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
        at se.springmobil.groupadmin.servlets.ControlServlet.createManagementSession(ControlServlet.
java:496)
        at se.springmobil.groupadmin.servlets.ControlServlet.processRequest(ControlServlet.java:178)
        at se.springmobil.groupadmin.servlets.ControlServlet.doGet(ControlServlet.java:444)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.j
ava:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:568)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
        at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
        at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:283)
        at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)
        at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)
        at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
        at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:507)
        at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:476)
        at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
        at java.sql.DriverManager.getDriver(DriverManager.java:253)
        at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1143)
        ... 23 more

My server.xml looks like this:

<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <Listener className="org.apache.catalina.core.JasperListener" />
  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

  <GlobalNamingResources>
    <Environment
              description=""
              name="configdir"
              type="java.lang.String"
              value="/etc/myapp"/>
    <Environment
              description=""
              name="ior_file"
              type="java.lang.String"
              value="/etc/myapp/direct.ior"/>
    <Resource
              name="jdbc/springmobil_db"
              type="javax.sql.DataSource"
              password="mypasswd"
              driverClassName="org.postgresql.Driver"
              maxIdle="2"
              maxWait="5000"
              validationQuery="SELECT 1"
              username="myapp"
              url="jdbc:postgresql://10.10.120.80/myapp_db"
              maxActive="4"/>
    <Resource
              auth="Container"
              description="User database that can be updated and saved"
              name="UserDatabase"
              type="org.apache.catalina.UserDatabase"
              pathname="conf/tomcat-users.xml"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"/>
  </GlobalNamingResources>

  <Service name="Catalina">
        <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

   <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

    <Engine name="Catalina" defaultHost="localhost">

      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase"/>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">

        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
      </Host>

      <Host name="myapp.mydomain.com" appBase="webapps/myapp"
        unpackWARs="true" autoDeploy="true"
        xmlValidation="false" xmlNamespaceAware="false">

        <Context path="" docBase="" debug="0" reloadable="true"/>

        <Valve className="org.apache.catalina.valves.AccessLogValve"
                 directory="logs"  prefix="vaxeladmin_access_log." suffix=".txt"
                 pattern="common" resolveHosts="false"/>
      </Host>

    </Engine>
  </Service>
</Server>

If I remove the row,
<Context path="" docBase="" debug="0" reloadable="true"/>
from myapp.mydomain.com vhost I get the following error in catalina.out,

Apr 10, 2008 4:06:34 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 806 ms
Apr 10, 2008 4:06:34 AM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Apr 10, 2008 4:06:34 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.16
Apr 10, 2008 4:06:35 AM org.apache.catalina.core.StandardContext resourcesStart
SEVERE: Error starting static Resources
java.lang.IllegalArgumentException: Document base /usr/local/tomcat/webapps/myapp/myapp does not exist or is not a readable directory
        at org.apache.naming.resources.FileDirContext.setDocBase(FileDirContext.java:141)
        at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:3957)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4126)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
        at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626)
        at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1147)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
        at org.apache.catalina.core.StandardService.start(StandardService.java:516)
        at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
        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:597)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
        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:597)
        at org.apache.commons.daemon.support.DaemonLoader.start(DaemonLoader.java:177)
Apr 10, 2008 4:06:35 AM org.apache.catalina.core.StandardContext start
SEVERE: Error in resourceStart()
Apr 10, 2008 4:06:35 AM org.apache.catalina.core.StandardContext start
SEVERE: Error getConfigured
Apr 10, 2008 4:06:35 AM org.apache.catalina.core.StandardContext start
SEVERE: Context [/acdadmin] startup failed due to previous errors
Apr 10, 2008 4:06:35 AM org.apache.catalina.core.StandardContext stop
INFO: Container org.apache.catalina.core.ContainerBase.[Catalina].[myapp.mydomain.com].[/myapp] has not been started
Apr 10, 2008 4:06:37 AM org.apache.catalina.startup.ContextConfig validateSecurityRoles
Apr 10, 2008 4:06:38 AM org.apache.catalina.core.StandardContext addApplicationListener
INFO: The listener "listeners.ContextListener" is already configured for this context. The duplicate definition has been ignored.
Apr 10, 2008 4:06:38 AM org.apache.catalina.core.StandardContext addApplicationListener
INFO: The listener "listeners.SessionListener" is already configured for this context. The duplicate definition has been ignored.
ContextListener: attributeAdded('com.sun.faces.ApplicationAssociate', 'com.sun.faces.application.ApplicationAssociate@1de45e2')
Apr 10, 2008 4:06:38 AM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Apr 10, 2008 4:06:38 AM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Apr 10, 2008 4:06:38 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Apr 10, 2008 4:06:38 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/45  config=null
Apr 10, 2008 4:06:38 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 4156 ms

It says that it cant find webapps/myapp/myapp, but I have only specified it once, what I can see.
What am I doing wrong here?

If I remove webapps/myapp from my vhost config, and just put "webapps" there I get the standard default tomcat web page, which is not good enough :)

I am using the same jsp-files for database connection, and the same app, on another server (dev), and it works.
The only difference is that I only have one vhost, the default localhost, on that server.

Have anyone else had this problem?

Thanks in advance!

Best regards,
Dan

RE: [SOLVED] tomcat not able to connect to postgresql?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Dan Eriksson [mailto:Dan.Eriksson@springmobil.se] 
> Subject: RE: [SOLVED] tomcat not able to connect to postgresql?
> 
> Not sure about the context yet though, as I want to be able to 
> use the same parameters for some other applications and not be 
> dependent on the developers to do configuration changes as we 
> use war files to pack the applications.

If you're specifying <Resource> elements that all webapps should have
access to, use <GlobalNamingResources> with embedded <Resource> elements
in server.xml and just a <ResourceLink> in each webapp:
http://tomcat.apache.org/tomcat-6.0-doc/config/globalresources.html

If other configuration parameters are to be used for all webapps, you
can place them in conf/context.xml, and they will be picked up for all.

You can also override a <Context> element in a webapp's
META-INF/context.xml file with one in a
conf/Catalina/[host]/[appname].xml file.  However, this may be
overwritten during redeployment.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: [SOLVED] tomcat not able to connect to postgresql?

Posted by Dan Eriksson <Da...@springmobil.se>.
Hi Chuck,
Thanks for the input!

I changed the appBase="webapps" and docBase="myapp".

Not sure about the context yet though, as I want to be able to use the
same parameters for some other applications and not be dependent on the
developers to do configuration changes as we use war files to pack the
applications.
I guess there are other alternatives as well to accomplish this, and I
will look at it when I have more time :)

Best regards,
Dan


-----Original Message-----
From: Caldarale, Charles R [mailto:Chuck.Caldarale@unisys.com] 
Sent: Thursday, April 10, 2008 3:30 PM
To: Tomcat Users List
Subject: RE: [SOLVED] tomcat not able to connect to postgresql?

> From: Dan Eriksson [mailto:Dan.Eriksson@springmobil.se] 
> Subject: [SOLVED] tomcat not able to connect to postgresql?
> 
>       <Host name="myapp.mydomain.com" appBase="webapps/myapp"
>         unpackWARs="true" autoDeploy="true"
>         xmlValidation="false" xmlNamespaceAware="false">
>         <Context path="" docBase="" debug="0" reloadable="true">

You may have fixed your DB access issue, but the above config contains a
serious problem that will likely bite you in the future.  A docBase
attribute (explicit or implicit) must never be empty; in your case it's
the same as the <Host> appBase, which creates serious internal grief for
Tomcat.  The proper setting would be appBase="webapps" and
docBase="myapp".

The above also places the <Context> element in server.xml, which has
been strongly discouraged for several years, and shouldn't be used by
any current implementation.  Since you apparently want this webapp to be
the default one, it should be located in webapps/ROOT, not
webapps/myapp, and the <Context> element should be in
webapps/ROOT/META-INF/context.xml, without the path and docBase
attributes.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: [SOLVED] tomcat not able to connect to postgresql?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Dan Eriksson [mailto:Dan.Eriksson@springmobil.se] 
> Subject: [SOLVED] tomcat not able to connect to postgresql?
> 
>       <Host name="myapp.mydomain.com" appBase="webapps/myapp"
>         unpackWARs="true" autoDeploy="true"
>         xmlValidation="false" xmlNamespaceAware="false">
>         <Context path="" docBase="" debug="0" reloadable="true">

You may have fixed your DB access issue, but the above config contains a
serious problem that will likely bite you in the future.  A docBase
attribute (explicit or implicit) must never be empty; in your case it's
the same as the <Host> appBase, which creates serious internal grief for
Tomcat.  The proper setting would be appBase="webapps" and
docBase="myapp".

The above also places the <Context> element in server.xml, which has
been strongly discouraged for several years, and shouldn't be used by
any current implementation.  Since you apparently want this webapp to be
the default one, it should be located in webapps/ROOT, not
webapps/myapp, and the <Context> element should be in
webapps/ROOT/META-INF/context.xml, without the path and docBase
attributes.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


[SOLVED] tomcat not able to connect to postgresql?

Posted by Dan Eriksson <Da...@springmobil.se>.
Hi Gabe,
Thanks for the fast answer!

-----Original Message-----
From: Gabe Wong [mailto:gabrielw@ngasi.com]
Sent: Thu 4/10/2008 4:29 AM
To: Tomcat Users List
Subject: Re: tomcat not able to connect to postgresql?
 
Dan Eriksson wrote:
>> If I try to connect to my vhost now everything looks ok, no errors anywhere, but when I try to login I get a message that the database is not online and in my logfile I see this:
>>
>> org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect UR
>>   
>Dan,
>This has been discussed many times before. Usually adding the database 
>driver to $TOMCAT_HOME/lib or $TOMCAT_HOME/common/lib
>solves the problem.
>Also further information maybe found at the following URL from the 
>mailing list archive, which is a good way to search for previously 
>discussed issues and solutions:
>http://marc.info/?l=tomcat-user&m=119454595817475&w=2

Indeed, I missed that one.
Adding everything from my lib dir to common/lib didn't solve it though.

I went through the documentation again,
http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html#Database%20Connection%20Pool%20(DBCP)%20Configurations
Under the postgresql there are two different configurations, first a generic resource that can be shared, which was what I was trying, and one that is specific resource per vhost.
I re-made the configuration to be specific per vhost instead, so my vhost configuration looked like this instead:

      <Host name="myapp.mydomain.com" appBase="webapps/myapp"
        unpackWARs="true" autoDeploy="true"
        xmlValidation="false" xmlNamespaceAware="false">

        <Context path="" docBase="" debug="0" reloadable="true">
    <Resource
              name="jdbc/springmobil_db"
              type="javax.sql.DataSource"
              password="mypasswd"
              driverClassName="org.postgresql.Driver"
              maxIdle="2"
              maxWait="5000"
              validationQuery="SELECT 1"
              username="myapp"
              url="jdbc:postgresql://10.10.120.80/myapp_db"
              maxActive="4"/>
        </Context>
        <Valve className="org.apache.catalina.valves.AccessLogValve"
                 directory="logs"  prefix="vaxeladmin_access_log." suffix=".txt"
                 pattern="common" resolveHosts="false"/>
      </Host>

After doing this it started to work as it should.

But if someone can explain why the generic resource didn't work it would be greatly appreciated!

Best regards,
Dan


Re: tomcat not able to connect to postgresql?

Posted by Gabe Wong <ga...@ngasi.com>.
Dan Eriksson wrote:
> Hi list!
>
> I am trying to configure apache + tomcat using mod_jk on different machines with virtual hosts, i.e one frontend running apache (2.2.3-4+etch4), one backend running tomcat 6 (binary apache-tomcat-6.0.16) with postgresql (postgresql-8.1, 8.1.11-0etch1) on debian etch.
>
> My virtual host is called myapp.mydomain.com.
>
> The problem is that when I am using context in my virtual host config for tomcat I receive the following in my logfile, catalina.out,
>
> javax.naming.NamingException: Cannot create resource instance
>         at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:143)
>         at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
>         at org.apache.naming.NamingContext.lookup(NamingContext.java:793)
>         at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
>         at se.springmobil.groupadmin.servlets.ControlServlet.init(ControlServlet.java:86)
>         at javax.servlet.GenericServlet.init(GenericServlet.java:212)
>         at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
>         at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
>         at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058)
>         at org.apache.catalina.core.StandardContext.start(StandardContext.java:4364)
>         at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
>         at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
>         at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
>         at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
>         at org.apache.catalina.core.StandardService.start(StandardService.java:516)
>         at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
>         at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
>         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:597)
>         at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
>         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:597)
>         at org.apache.commons.daemon.support.DaemonLoader.start(DaemonLoader.java:177)
> ContextListener: attributeAdded('com.sun.faces.ApplicationAssociate', 'com.sun.faces.application.ApplicationAssociate@ecb67f')
>
> If I try to connect to my vhost now everything looks ok, no errors anywhere, but when I try to login I get a message that the database is not online and in my logfile I see this:
>
> org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect UR
>   
Dan,
This has been discussed many times before. Usually adding the database 
driver to $TOMCAT_HOME/lib or $TOMCAT_HOME/common/lib
solves the problem.
Also further information maybe found at the following URL from the 
mailing list archive, which is a good way to search for previously 
discussed issues and solutions:
http://marc.info/?l=tomcat-user&m=119454595817475&w=2



-- 
Regards

Gabe Wong
NGASI AppServer Manager
JAVA AUTOMATION and SaaS Enablement
http://www.ngasi.com
NEW! 8.0 - Centrally manage multiple physical servers


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: tomcat not able to connect to postgresql?

Posted by Dan Eriksson <Da...@springmobil.se>.
Hi again,
I thought I would give some complementing stuff,

I am using the following jdbc driver, which is located in tomcat/lib,
postgresql-8.3-603.jdbc4.jar

I have also tried,
postgresql-8.0-313.jdbc3.jar

I am using jdk-6u5-linux-i586.bin version of java.

To clarify one thing, if I only use "webapps" as appBase in my vhost, I am able to access my application through, myapp.mydomain.com/myapp, and the database connection seems to be working perfectly, but... thats not what I want to do :)

Hope someone can send me in the right direction!

Best regards,
Dan




-----Original Message-----
From: Dan Eriksson [mailto:Dan.Eriksson@springmobil.se]
Sent: Thu 4/10/2008 4:15 AM
To: users@tomcat.apache.org
Subject: tomcat not able to connect to postgresql?
 
Hi list!

I am trying to configure apache + tomcat using mod_jk on different machines with virtual hosts, i.e one frontend running apache (2.2.3-4+etch4), one backend running tomcat 6 (binary apache-tomcat-6.0.16) with postgresql (postgresql-8.1, 8.1.11-0etch1) on debian etch.

My virtual host is called myapp.mydomain.com.

The problem is that when I am using context in my virtual host config for tomcat I receive the following in my logfile, catalina.out,

javax.naming.NamingException: Cannot create resource instance
        at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:143)
        at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:793)
        at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
        at se.springmobil.groupadmin.servlets.ControlServlet.init(ControlServlet.java:86)
        at javax.servlet.GenericServlet.init(GenericServlet.java:212)
        at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
        at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
        at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4364)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
        at org.apache.catalina.core.StandardService.start(StandardService.java:516)
        at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
        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:597)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
        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:597)
        at org.apache.commons.daemon.support.DaemonLoader.start(DaemonLoader.java:177)
ContextListener: attributeAdded('com.sun.faces.ApplicationAssociate', 'com.sun.faces.application.ApplicationAssociate@ecb67f')

If I try to connect to my vhost now everything looks ok, no errors anywhere, but when I try to login I get a message that the database is not online and in my logfile I see this:

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect UR
L 'null'
        at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1150)
        at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
        at se.springmobil.groupadmin.servlets.ControlServlet.createManagementSession(ControlServlet.
java:496)
        at se.springmobil.groupadmin.servlets.ControlServlet.processRequest(ControlServlet.java:178)
        at se.springmobil.groupadmin.servlets.ControlServlet.doGet(ControlServlet.java:444)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.j
ava:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:568)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
        at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
        at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:283)
        at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)
        at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)
        at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
        at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:507)
        at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:476)
        at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
        at java.sql.DriverManager.getDriver(DriverManager.java:253)
        at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1143)
        ... 23 more

My server.xml looks like this:

<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <Listener className="org.apache.catalina.core.JasperListener" />
  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

  <GlobalNamingResources>
    <Environment
              description=""
              name="configdir"
              type="java.lang.String"
              value="/etc/myapp"/>
    <Environment
              description=""
              name="ior_file"
              type="java.lang.String"
              value="/etc/myapp/direct.ior"/>
    <Resource
              name="jdbc/springmobil_db"
              type="javax.sql.DataSource"
              password="mypasswd"
              driverClassName="org.postgresql.Driver"
              maxIdle="2"
              maxWait="5000"
              validationQuery="SELECT 1"
              username="myapp"
              url="jdbc:postgresql://10.10.120.80/myapp_db"
              maxActive="4"/>
    <Resource
              auth="Container"
              description="User database that can be updated and saved"
              name="UserDatabase"
              type="org.apache.catalina.UserDatabase"
              pathname="conf/tomcat-users.xml"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"/>
  </GlobalNamingResources>

  <Service name="Catalina">
        <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

   <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

    <Engine name="Catalina" defaultHost="localhost">

      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase"/>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">

        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
      </Host>

      <Host name="myapp.mydomain.com" appBase="webapps/myapp"
        unpackWARs="true" autoDeploy="true"
        xmlValidation="false" xmlNamespaceAware="false">

        <Context path="" docBase="" debug="0" reloadable="true"/>

        <Valve className="org.apache.catalina.valves.AccessLogValve"
                 directory="logs"  prefix="vaxeladmin_access_log." suffix=".txt"
                 pattern="common" resolveHosts="false"/>
      </Host>

    </Engine>
  </Service>
</Server>

If I remove the row,
<Context path="" docBase="" debug="0" reloadable="true"/>
from myapp.mydomain.com vhost I get the following error in catalina.out,

Apr 10, 2008 4:06:34 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 806 ms
Apr 10, 2008 4:06:34 AM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Apr 10, 2008 4:06:34 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.16
Apr 10, 2008 4:06:35 AM org.apache.catalina.core.StandardContext resourcesStart
SEVERE: Error starting static Resources
java.lang.IllegalArgumentException: Document base /usr/local/tomcat/webapps/myapp/myapp does not exist or is not a readable directory
        at org.apache.naming.resources.FileDirContext.setDocBase(FileDirContext.java:141)
        at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:3957)
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:4126)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
        at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626)
        at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
        at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1147)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
        at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
        at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
        at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
        at org.apache.catalina.core.StandardService.start(StandardService.java:516)
        at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
        at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
        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:597)
        at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
        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:597)
        at org.apache.commons.daemon.support.DaemonLoader.start(DaemonLoader.java:177)
Apr 10, 2008 4:06:35 AM org.apache.catalina.core.StandardContext start
SEVERE: Error in resourceStart()
Apr 10, 2008 4:06:35 AM org.apache.catalina.core.StandardContext start
SEVERE: Error getConfigured
Apr 10, 2008 4:06:35 AM org.apache.catalina.core.StandardContext start
SEVERE: Context [/acdadmin] startup failed due to previous errors
Apr 10, 2008 4:06:35 AM org.apache.catalina.core.StandardContext stop
INFO: Container org.apache.catalina.core.ContainerBase.[Catalina].[myapp.mydomain.com].[/myapp] has not been started
Apr 10, 2008 4:06:37 AM org.apache.catalina.startup.ContextConfig validateSecurityRoles
Apr 10, 2008 4:06:38 AM org.apache.catalina.core.StandardContext addApplicationListener
INFO: The listener "listeners.ContextListener" is already configured for this context. The duplicate definition has been ignored.
Apr 10, 2008 4:06:38 AM org.apache.catalina.core.StandardContext addApplicationListener
INFO: The listener "listeners.SessionListener" is already configured for this context. The duplicate definition has been ignored.
ContextListener: attributeAdded('com.sun.faces.ApplicationAssociate', 'com.sun.faces.application.ApplicationAssociate@1de45e2')
Apr 10, 2008 4:06:38 AM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Apr 10, 2008 4:06:38 AM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Apr 10, 2008 4:06:38 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Apr 10, 2008 4:06:38 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/45  config=null
Apr 10, 2008 4:06:38 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 4156 ms

It says that it cant find webapps/myapp/myapp, but I have only specified it once, what I can see.
What am I doing wrong here?

If I remove webapps/myapp from my vhost config, and just put "webapps" there I get the standard default tomcat web page, which is not good enough :)

I am using the same jsp-files for database connection, and the same app, on another server (dev), and it works.
The only difference is that I only have one vhost, the default localhost, on that server.

Have anyone else had this problem?

Thanks in advance!

Best regards,
Dan