You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Scott Purcell <sp...@vertisinc.com> on 2006/06/28 15:33:20 UTC

Tomcat 5.5 JNDI Question Using Admin

Hello,

 

I am receiving errors when configuring a JNDI resource for my database
using Tomcat 5.5 on a Windoz box. I used the admin interface and entered
the following data:

in admin screen

under  Data Sources

JNDI Name= jdbc/BuilderDB

Driver com.mysql.jdbc.Driver

Data Source URL=jdbc:mysql://localhost/builder

JDBC Driver Class=com.mysql.jdbc.Driver

 

Then I made sure my driver was in

common/lib/mysql-connector-java-3.1.12

 

 

Then went to the web.xml file added my resource

web.xml

  <resource-ref>
      <description>DB Connection</description>
      <res-ref-name>jdbc/BuilderDB</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
  </resource-ref>

 

 

After committing the change in the admin module, it updated the
server.xml and added this the <Resource (see below).

When I try and get a jndi connection doing a lookup, I get this error
(see below).

 

As I read the docs for 5.5, and I do not see any examples. Does anyone
see any problems with this, or know what may cause this error?

 

 

Thanks,

Scott

 

 

 

 

error

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC
driver of class '' for connect URL 'null'
 at
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSo
urce.java:780)
 at
org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSourc
e.java:540)
 at foo.DBTest.init(DBTest.java:23)
 at org.apache.jsp.test_jsp._jspService(test_jsp.java:51)
 at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
 at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.ja
va:332)
 at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
 at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
 at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
tionFilterChain.java:252)
 at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
erChain.java:173)
 at
com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.
java:142)

 

 

 

 

 

Server.xml

<?xml version="1.0" encoding="UTF-8"?>
<Server>
  <Listener className="org.apache.catalina.core.AprLifecycleListener"/>
  <Listener
className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/
>
  <Listener
className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"
/>
  <Listener
className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
  <GlobalNamingResources>
    <Environment
      name="simpleValue"
      type="java.lang.Integer"
      value="30"/>
    <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"/>
    <Resource
      name="jdbc/BuilderDB"
      type="javax.sql.DataSource"
      password="admin"
      driverClassName="com.mysql.jdbc.Driver"
      maxIdle="2"
      maxWait="5000"
      validationQuery="select * from test
"
      username="root"
      url="jdbc:mysql://localhost/builder"
      maxActive="4"/>
  </GlobalNamingResources>
  <Service
      name="Catalina">
    <Connector
        port="8080"
        redirectPort="8443"
        minSpareThreads="25"
        connectionTimeout="20000"
        maxThreads="150"
        maxSpareThreads="75">
    </Connector>
    <Connector
        port="8009"
        redirectPort="8443"
        protocol="AJP/1.3">
    </Connector>
    <Engine
        defaultHost="localhost"
        name="Catalina">
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
      <Host
          appBase="webapps"
          name="localhost">
      </Host>
    </Engine>
  </Service>
</Server>

 

 


Re: Tomcat 5.5 JNDI Question Using Admin

Posted by Pid <p...@pidster.com>.
You can also configure DBCP to do some connection pooling, without much
effort. I'd recommend avoiding the root user for your DB connection.

The error message you saw is a poor one, but common.

In your global resources:

    <Resource
      name="jdbc/BuilderDB"
      type="javax.sql.DataSource"
      driverClassName="com.mysql.jdbc.Driver"
      factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
      maxActive="10"
      maxIdle="1"
      maxWait="5000"
      minIdle="1"
      initialSize="10"
      removeAbandoned="true"
      removeAbandonedTimeout="60"
      logAbandoned="true"
      validationQuery="select count(*) from test"
      username="root"
      password="admin"
      url="jdbc:mysql://localhost/builder"
      />

A DataSource in your <Context...>

  <ResourceLink
    debug="5"
    name="jdbc/BuilderDB"
    global="jdbc/BuilderDB"
    type="javax.sql.DataSource"/>

A Realm in your <Engine...> or <Host...>

      <Realm className="org.apache.catalina.realm.DataSourceRealm"
        dataSourceName="jdbc/BuilderDB"
        roleNameCol="role_name"
	userNameCol="user_name"
	userCredCol="user_pass"
        userRoleTable="user_roles"
	userTable="users"/>


Pid wrote:
> You need a ResourceLink in the Host or Context, to make the global
> resource available.
> 
> Does the Context xml file contain this?
> 
> 
> 
> Scott Purcell wrote:
>> Hello,
>>
>>  
>>
>> I am receiving errors when configuring a JNDI resource for my database
>> using Tomcat 5.5 on a Windoz box. I used the admin interface and entered
>> the following data:
>>
>> in admin screen
>>
>> under  Data Sources
>>
>> JNDI Name= jdbc/BuilderDB
>>
>> Driver com.mysql.jdbc.Driver
>>
>> Data Source URL=jdbc:mysql://localhost/builder
>>
>> JDBC Driver Class=com.mysql.jdbc.Driver
>>
>>  
>>
>> Then I made sure my driver was in
>>
>> common/lib/mysql-connector-java-3.1.12
>>
>>  
>>
>>  
>>
>> Then went to the web.xml file added my resource
>>
>> web.xml
>>
>>   <resource-ref>
>>       <description>DB Connection</description>
>>       <res-ref-name>jdbc/BuilderDB</res-ref-name>
>>       <res-type>javax.sql.DataSource</res-type>
>>       <res-auth>Container</res-auth>
>>   </resource-ref>
>>
>>  
>>
>>  
>>
>> After committing the change in the admin module, it updated the
>> server.xml and added this the <Resource (see below).
>>
>> When I try and get a jndi connection doing a lookup, I get this error
>> (see below).
>>
>>  
>>
>> As I read the docs for 5.5, and I do not see any examples. Does anyone
>> see any problems with this, or know what may cause this error?
>>
>>  
>>
>>  
>>
>> Thanks,
>>
>> Scott
>>
>>  
>>
>>  
>>
>>  
>>
>>  
>>
>> error
>>
>> org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC
>> driver of class '' for connect URL 'null'
>>  at
>> org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSo
>> urce.java:780)
>>  at
>> org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSourc
>> e.java:540)
>>  at foo.DBTest.init(DBTest.java:23)
>>  at org.apache.jsp.test_jsp._jspService(test_jsp.java:51)
>>  at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
>>  at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>>  at
>> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.ja
>> va:332)
>>  at
>> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
>>  at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
>>  at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>>  at
>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
>> tionFilterChain.java:252)
>>  at
>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
>> erChain.java:173)
>>  at
>> com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.
>> java:142)
>>
>>  
>>
>>  
>>
>>  
>>
>>  
>>
>>  
>>
>> Server.xml
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <Server>
>>   <Listener className="org.apache.catalina.core.AprLifecycleListener"/>
>>   <Listener
>> className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/
>>   <Listener
>> className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"
>> />
>>   <Listener
>> className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
>>   <GlobalNamingResources>
>>     <Environment
>>       name="simpleValue"
>>       type="java.lang.Integer"
>>       value="30"/>
>>     <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"/>
>>     <Resource
>>       name="jdbc/BuilderDB"
>>       type="javax.sql.DataSource"
>>       password="admin"
>>       driverClassName="com.mysql.jdbc.Driver"
>>       maxIdle="2"
>>       maxWait="5000"
>>       validationQuery="select * from test
>> "
>>       username="root"
>>       url="jdbc:mysql://localhost/builder"
>>       maxActive="4"/>
>>   </GlobalNamingResources>
>>   <Service
>>       name="Catalina">
>>     <Connector
>>         port="8080"
>>         redirectPort="8443"
>>         minSpareThreads="25"
>>         connectionTimeout="20000"
>>         maxThreads="150"
>>         maxSpareThreads="75">
>>     </Connector>
>>     <Connector
>>         port="8009"
>>         redirectPort="8443"
>>         protocol="AJP/1.3">
>>     </Connector>
>>     <Engine
>>         defaultHost="localhost"
>>         name="Catalina">
>>       <Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
>>       <Host
>>           appBase="webapps"
>>           name="localhost">
>>       </Host>
>>     </Engine>
>>   </Service>
>> </Server>
>>
>>  
>>
>>  
>>
>>
> 
> ---------------------------------------------------------------------
> 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: Tomcat 5.5 JNDI Question Using Admin

Posted by Pid <p...@pidster.com>.
You need a ResourceLink in the Host or Context, to make the global
resource available.

Does the Context xml file contain this?



Scott Purcell wrote:
> Hello,
> 
>  
> 
> I am receiving errors when configuring a JNDI resource for my database
> using Tomcat 5.5 on a Windoz box. I used the admin interface and entered
> the following data:
> 
> in admin screen
> 
> under  Data Sources
> 
> JNDI Name= jdbc/BuilderDB
> 
> Driver com.mysql.jdbc.Driver
> 
> Data Source URL=jdbc:mysql://localhost/builder
> 
> JDBC Driver Class=com.mysql.jdbc.Driver
> 
>  
> 
> Then I made sure my driver was in
> 
> common/lib/mysql-connector-java-3.1.12
> 
>  
> 
>  
> 
> Then went to the web.xml file added my resource
> 
> web.xml
> 
>   <resource-ref>
>       <description>DB Connection</description>
>       <res-ref-name>jdbc/BuilderDB</res-ref-name>
>       <res-type>javax.sql.DataSource</res-type>
>       <res-auth>Container</res-auth>
>   </resource-ref>
> 
>  
> 
>  
> 
> After committing the change in the admin module, it updated the
> server.xml and added this the <Resource (see below).
> 
> When I try and get a jndi connection doing a lookup, I get this error
> (see below).
> 
>  
> 
> As I read the docs for 5.5, and I do not see any examples. Does anyone
> see any problems with this, or know what may cause this error?
> 
>  
> 
>  
> 
> Thanks,
> 
> Scott
> 
>  
> 
>  
> 
>  
> 
>  
> 
> error
> 
> org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC
> driver of class '' for connect URL 'null'
>  at
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSo
> urce.java:780)
>  at
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSourc
> e.java:540)
>  at foo.DBTest.init(DBTest.java:23)
>  at org.apache.jsp.test_jsp._jspService(test_jsp.java:51)
>  at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
>  at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>  at
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.ja
> va:332)
>  at
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
>  at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
>  at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>  at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
> tionFilterChain.java:252)
>  at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
> erChain.java:173)
>  at
> com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.
> java:142)
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
> Server.xml
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <Server>
>   <Listener className="org.apache.catalina.core.AprLifecycleListener"/>
>   <Listener
> className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/
>   <Listener
> className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"
> />
>   <Listener
> className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
>   <GlobalNamingResources>
>     <Environment
>       name="simpleValue"
>       type="java.lang.Integer"
>       value="30"/>
>     <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"/>
>     <Resource
>       name="jdbc/BuilderDB"
>       type="javax.sql.DataSource"
>       password="admin"
>       driverClassName="com.mysql.jdbc.Driver"
>       maxIdle="2"
>       maxWait="5000"
>       validationQuery="select * from test
> "
>       username="root"
>       url="jdbc:mysql://localhost/builder"
>       maxActive="4"/>
>   </GlobalNamingResources>
>   <Service
>       name="Catalina">
>     <Connector
>         port="8080"
>         redirectPort="8443"
>         minSpareThreads="25"
>         connectionTimeout="20000"
>         maxThreads="150"
>         maxSpareThreads="75">
>     </Connector>
>     <Connector
>         port="8009"
>         redirectPort="8443"
>         protocol="AJP/1.3">
>     </Connector>
>     <Engine
>         defaultHost="localhost"
>         name="Catalina">
>       <Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
>       <Host
>           appBase="webapps"
>           name="localhost">
>       </Host>
>     </Engine>
>   </Service>
> </Server>
> 
>  
> 
>  
> 
> 

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