You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jean-Louis Mateo <je...@bull.net> on 2015/02/06 12:27:48 UTC

Issue when using tomcat JDBC Connection Pool with a shared resource

Hi,

I would like to use the Tomcat JDBC Connection Pool with a shared resource so I've read :
 http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html#Standalone and http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Resource_Links

.... and tried to do the same but when I try to access to my servlet I get the following message:

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
                at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
                at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
                at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
                at testPackage.DBTest.doGet(DBTest.java:62)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
                at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
                at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
                at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
                at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
                at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:612)
                at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
                at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
                at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
                at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
                at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
                at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
                at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
                at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
                at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
                at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
                at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
                at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:524)
                at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:493)
                at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
                at java.sql.DriverManager.getDriver(DriverManager.java:262)
                at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
                ... 25 more
--------------------

Environment :
Win 7
Java - jdk 1.7.0.65
Tomcat - 7.0.57
MySQL - 5.1.18

--------------------

Tomcat service properties:
-Dcatalina.home=Y:\Programs\Tomcat\Tomcat7
-Dcatalina.base=Y:\00-Prod\data\catalina
-Djava.endorsed.dirs=Y:\Programs\Tomcat\Tomcat7\endorsed
-Djava.io.tmpdir=Y:\Programs\Tomcat\Tomcat7\temp
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.util.logging.config.file=Y:\Programs\Tomcat\Tomcat7\conf\logging.properties
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=8099
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-XX:MaxPermSize=512m

--------------------

CATALINA_HOME/lib contents
...
tomcat-dbcp.jar
tomcat-jdbc.jar
...

--------------------

CATALINA_BASE/lib contents:
mysql-connector-java-5.1.18-bin.jar
--------------------

CATALINA_BASE/conf/server.xml
...
...
  <GlobalNamingResources>
                               ...
-->
                <Resource          name="sharedDataSource"
                                               global="sharedDataSource"
                                               auth="Container"
                                               type="javax.sql.DataSource"
                                               factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
                                               driverClassName="com.mysql.jdbc.Driver"
                                               initialSize="2" minIdle="4" maxActive="8" maxIdle="4" maxWait="10000"
                                               username="javauser" password="javadude"
                                               url="jdbc:mysql://localhost:3306/javatest"/>

  </GlobalNamingResources>

...
...
--------------------

CATALINA_BASE/conf/Catalina/localhost/test-app.xml


<?xml version='1.0' encoding='utf-8'?>
<Context path="/test-app" privileged="true">
                ...
                ...
    <!-- url: The JDBC connection url for connecting to your MySQL database. -->
                <ResourceLink  name="jdbc/LocalTestDB"
                                               global="sharedDataSource"
                                               type="javax.sql.DataSource"/>

                ...
                ...
</Context>
--------------------

DBTest.java excerpt :

package testPackage;

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
....

@WebServlet(name="DBTest", urlPatterns="/DatabaseTest")
public class DBTest extends HttpServlet {

                protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                               // TODO Auto-generated method stub

                    PrintWriter out = response.getWriter();

                               DataSource ds;
                               Connection con;
                               con = null;

                               String title = "Database Result";
                               ...
                               ...
                               try {

                                               Context ctx = new InitialContext();
                                               Context initContext  = (Context) ctx.lookup("java:/comp/env");
                                               ds = (DataSource) initContext.lookup("jdbc/TestDB");

<!-- line 62 --> con = ds.getConnection();
                               ...
                               ...

--------------------

Note that when I don't share the datasource (Resource element is in test-app.xml and no ResourceLink in server.xml), it works fine.

Any ideas on where should I look at ?

Best Regards


Jean-Louis Matéo

RE: Issue when using tomcat JDBC Connection Pool with a shared resource

Posted by MW...@loftware.com.

> -----Original Message-----
> From: Daniel Mikusa [mailto:dmikusa@pivotal.io]
> Sent: Friday, February 06, 2015 8:06 AM
> To: Tomcat Users List
> Subject: Re: Issue when using tomcat JDBC Connection Pool with a shared
> resource
> 
> On Fri, Feb 6, 2015 at 6:27 AM, Jean-Louis Mateo <jean-
> louis.mateo@bull.net>
> wrote:
> 
> >  Hi,
> >
> >
> >
> > I would like to use the Tomcat JDBC Connection Pool with a shared
> > resource so I’ve read :
> >
> >  http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html#Standalone and
> > http://tomcat.apache.org/tomcat-7.0-
> doc/config/context.html#Resource_L
> > inks
> >
> >
> >
> > …. and tried to do the same but when I try to access to my servlet I
> > get the following message:
> >
> >
> >
> > org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC
> > driver of class '' for connect URL 'null'
> >
> 
> A couple odd things here...
> 
> 1.) It's trying to use DBCP, not the jdbc connection pool.
> 2.) It has no url or driver set.
> 
> 
> >                  at
> >
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(Ba
> > sicDataSource.java:1452)
> >
> >                 at
> >
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicData
> > Source.java:1371)
> >
> >                 at
> >
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSou
> > rce.java:1044)
> >
> >                 at testPackage.DBTest.doGet(DBTest.java:62)
> >
> >                 at
> > javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
> >
> >                 at
> > javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
> >
> >                 at
> > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appli
> > cationFilterChain.java:303)
> >
> >                 at
> > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFi
> > lterChain.java:208)
> >
> >                 at
> > org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
> >
> >                 at
> > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appli
> > cationFilterChain.java:241)
> >
> >                 at
> > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFi
> > lterChain.java:208)
> >
> >                 at
> >
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
> a
> > lve.java:220)
> >
> >                 at
> >
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextVa
> > lve.java:122)
> >
> >                 at
> > org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authenticat
> > orBase.java:612)
> >
> >                 at
> > org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.ja
> > va:170)
> >
> >                 at
> > org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.ja
> > va:103)
> >
> >                 at
> > org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:9
> > 50)
> >
> >                 at
> > org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValv
> > e.java:116)
> >
> >                 at
> > org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java
> > :421)
> >
> >                 at
> > org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp1
> > 1Processor.java:1070)
> >
> >                 at
> >
> org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(A
> > bstractProtocol.java:611)
> >
> >                 at
> > org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint
> > .java:316)
> >
> >                 at
> > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.j
> > ava:1145)
> >
> >                 at
> > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.
> > java:615)
> >
> >                 at
> >
> org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThr
> > ead.java:61)
> >
> >                 at java.lang.Thread.run(Thread.java:745)
> >
> > Caused by: java.lang.NullPointerException
> >
> >                 at
> > sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:524)
> >
> >                 at
> > sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:493)
> >
> >                 at
> > sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
> >
> >                 at
> > java.sql.DriverManager.getDriver(DriverManager.java:262)
> >
> >                 at
> >
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(Ba
> > sicDataSource.java:1437)
> >
> >                 ... 25 more
> >
> > --------------------
> >
> >
> >
> > Environment :
> >
> > Win 7
> >
> > Java - jdk 1.7.0.65
> >
> > Tomcat - 7.0.57
> >
> > MySQL - 5.1.18
> >
> >
> >
> > --------------------
> >
> >
> >
> > Tomcat service properties:
> >
> > -Dcatalina.home=Y:\Programs\Tomcat\Tomcat7
> >
> > -Dcatalina.base=Y:\00-Prod\data\catalina
> >
> > -Djava.endorsed.dirs=Y:\Programs\Tomcat\Tomcat7\endorsed
> >
> > -Djava.io.tmpdir=Y:\Programs\Tomcat\Tomcat7\temp
> >
> > -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
> >
> >
> > -Djava.util.logging.config.file=Y:\Programs\Tomcat\Tomcat7\conf\loggin
> > g.properties
> >
> > -Dcom.sun.management.jmxremote
> >
> > -Dcom.sun.management.jmxremote.port=8099
> >
> > -Dcom.sun.management.jmxremote.ssl=false
> >
> > -Dcom.sun.management.jmxremote.authenticate=false
> >
> > -XX:MaxPermSize=512m
> >
> >
> >
> > --------------------
> >
> >
> >
> > CATALINA_HOME/lib contents
> >
> > …
> >
> > tomcat-dbcp.jar
> >
> > tomcat-jdbc.jar
> >
> > …
> >
> >
> >
> > --------------------
> >
> >
> >
> > CATALINA_BASE/lib contents:
> >
> > mysql-connector-java-5.1.18-bin.jar
> >
> > --------------------
> >
> >
> >
> > CATALINA_BASE/conf/server.xml
> >
> > ...
> >
> > …
> >
> >   <GlobalNamingResources>
> >
> >                                …
> >
> 
> What else do you have defined in this block?
> 
> 
> >  -->
> >
> >                 <Resource          name="sharedDataSource"
> >
> >                                                global="sharedDataSource"
> >
> 
> Not sure about this "global" attribute.  I don't believe it's an attribute of the
> pool.  Why did you add it?
> 
> 
> >                                                 auth="Container"
> >
> >                                                type="javax.sql.DataSource"
> >
> >
> > factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
> >
> >
> > driverClassName="com.mysql.jdbc.Driver"
> >
> >                                                initialSize="2"
> >
> 
> You have initialSize set to 2.  This should attempt to make connections when
> you start Tomcat.  Do you see any errors at that time?
> 
> 
> > minIdle="4" maxActive="8" maxIdle="4" maxWait="10000"
> >
> >                                                username="javauser"
> > password="javadude"
> >
> >
> > url="jdbc:mysql://localhost:3306/javatest"/>
> >
> >
> >
> >   </GlobalNamingResources>
> >
> >
> >
> > …
> >
> > ...
> >
> > --------------------
> >
> >
> >
> > CATALINA_BASE/conf/Catalina/localhost/test-app.xml
> >
> >
> >
> >
> >
> > <?xml version='1.0' encoding='utf-8'?>
> >
> > <Context path="/test-app" privileged="true">
> >
> 
> This is unrelated, but don't set "path" here.  The path attribute is ignore here.
> The path is determined by the name of the xml file, which just happens to be
> "test-app" as well.
> 
> Also what else do you have define in this file?
> 
> 
> >                  ...
> >
> >                 ...
> >
> >     <!-- url: The JDBC connection url for connecting to your MySQL
> > database. -->
> >
> >                 <ResourceLink  name="jdbc/LocalTestDB"
> >
> >                                                global="sharedDataSource"
> >
> >
> > type="javax.sql.DataSource"/>
> >
> >
> >
> >                 ...
> >
> >                 ...
> >
> > </Context>
> >
> > --------------------
> >
> 
> Do you have anything set in "conf/context.xml" or in your web.xml?
> 
> Dan
> 
> 
> >
> >
> > DBTest.java excerpt :
> >
> >
> >
> > package testPackage;
> >
> >
> >
> > import javax.servlet.*;
> >
> > import javax.servlet.annotation.WebServlet;
> >
> > import javax.servlet.http.*;
> >
> > import javax.naming.Context;
> >
> > import javax.naming.InitialContext;
> >
> > import javax.naming.NamingException;
> >
> > import javax.sql.DataSource;
> >
> >
> >
> > import java.sql.Connection;
> >
> > import java.sql.ResultSet;
> >
> > import java.sql.SQLException;
> >
> > import java.sql.Statement;
> >
> > ....
> >
> >
> >
> > @WebServlet(name="DBTest", urlPatterns="/DatabaseTest")
> >
> > public class DBTest extends HttpServlet {
> >
> >
> >
> >                 protected void doGet(HttpServletRequest request,
> > HttpServletResponse response) throws ServletException, IOException {
> >
> >                                // TODO Auto-generated method stub
> >
> >
> >
> >                     PrintWriter out = response.getWriter();
> >
> >
> >
> >                                DataSource ds;
> >
> >                                Connection con;
> >
> >                                con = null;
> >
> >
> >
> >                                String title = "Database Result";
> >
> >                                ...
> >
> >                                ...
> >
> >                                try {
> >
> >
> >
> >                                                Context ctx = new
> > InitialContext();
> >
> >                                                Context initContext  =
> > (Context) ctx.lookup("java:/comp/env");
> >
> >                                                ds = (DataSource)
> > initContext.lookup("jdbc/TestDB");
> >
> >
> >
> > <!-- line 62 --> con = ds.getConnection();
> >
> >                                ...
> >
> >                                ...
> >
> >
> >
> > --------------------
> >
> >
> >
> > Note that when I don’t share the datasource (Resource element is in
> > test-app.xml and no ResourceLink in server.xml), it works fine.
> >
> >
> >
> > Any ideas on where should I look at ?
> >
> >
> >
> > Best Regards
> >
> > [image: blue_strip]
> >
> >
> >
> > Jean-Louis Matéo
> >

Shouldn't this line be:

ds = (DataSource)initContext.lookup("jdbc/LocalTestDB");

(LocalTestDB vs. TestDB)?


Re: Issue when using tomcat JDBC Connection Pool with a shared resource

Posted by Daniel Mikusa <dm...@pivotal.io>.
On Fri, Feb 6, 2015 at 9:57 AM, Jean-Louis Mateo <je...@bull.net>
wrote:

> Hi Dan,
>
> Thank you for having replied to this issue.
> First of all, now it works fine but I would like to answer your
> questions...
>
> > Not sure about this "global" attribute.  I don't believe it's an
> attribute of the pool.  Why did you add it?
>         That's what I've read here
> http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Resource_Definitions


The "global" attribute is on the ResourceLink tag, not the Resource tag.


>
>
> > 2.) It has no url or driver set.
>         Thanks. The issue was here and  I should have read it more closely
> about the "name" property (at the same above url):
>                 "name: The name of the resource link to be created,
> relative to the java:comp/env context."
>                 So...
>                 Before, in my context file
>                 <ResourceLink  name="jdbc/LocalTestDB" <-------- E R R O
> R  this jndi name doesn't exist
>                                 global="sharedDataSource"
>                 type="javax.sql.DataSource"/>
>
>                 After, in my context file
>                 <ResourceLink   name="jdbc/TestDB" <----- That's the right
> name
>                 global="sharedDataSource"
>                 type="javax.sql.DataSource"/>
>
>                 Now it works fine
>
>         Note: In a way, you were right "global" property is no need in
> <GlobalNamingResources> (server.xml)
>                 Only "global" (from context.xml, ResourceLink) and "name"
> (from server.xml, <GlobalNamingResources-Resource>) are needed and have to
> match
>

Awesome!  Glad you caught that and were able to get it working.

Dan



>
> > You have initialSize set to 2.  This should attempt to make connections
> when you start Tomcat.  Do you see any errors at that time?
>         There were no errors. At launching time, the pool is well created
> with 2 connexions in LISTENING state (netstat -an)
>
> > This is unrelated, but don't set "path" here.  The path attribute is
> ignore here.  The path is determined by the name of the xml file, which
> just happens to be "test-app" as well.
>         OK. "path" is no longer set.
>
> > Do you have anything set in "conf/context.xml" or in your web.xml?
>         See the attached file
>
>
> Best Regards
>
> Jean-Louis Matéo
>
>
> -----Message d'origine-----
> De : Daniel Mikusa [mailto:dmikusa@pivotal.io]
> Envoyé : vendredi 6 février 2015 14:06
> À : Tomcat Users List
> Objet : Re: Issue when using tomcat JDBC Connection Pool with a shared
> resource
>
> On Fri, Feb 6, 2015 at 6:27 AM, Jean-Louis Mateo <
> jean-louis.mateo@bull.net>
> wrote:
>
> >  Hi,
> >
> >
> >
> > I would like to use the Tomcat JDBC Connection Pool with a shared
> > resource so I’ve read :
> >
> >  http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html#Standalone and
> > http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Resource_L
> > inks
> >
> >
> >
> > …. and tried to do the same but when I try to access to my servlet I
> > get the following message:
> >
> >
> >
> > org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC
> > driver of class '' for connect URL 'null'
> >
>
> A couple odd things here...
>
> 1.) It's trying to use DBCP, not the jdbc connection pool.
> 2.) It has no url or driver set.
>
>
> >                  at
> > org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(Ba
> > sicDataSource.java:1452)
> >
> >                 at
> > org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicData
> > Source.java:1371)
> >
> >                 at
> > org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSou
> > rce.java:1044)
> >
> >                 at testPackage.DBTest.doGet(DBTest.java:62)
> >
> >                 at
> > javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
> >
> >                 at
> > javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
> >
> >                 at
> > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appli
> > cationFilterChain.java:303)
> >
> >                 at
> > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFi
> > lterChain.java:208)
> >
> >                 at
> > org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
> >
> >                 at
> > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appli
> > cationFilterChain.java:241)
> >
> >                 at
> > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFi
> > lterChain.java:208)
> >
> >                 at
> > org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperVa
> > lve.java:220)
> >
> >                 at
> > org.apache.catalina.core.StandardContextValve.invoke(StandardContextVa
> > lve.java:122)
> >
> >                 at
> > org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authenticat
> > orBase.java:612)
> >
> >                 at
> > org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.ja
> > va:170)
> >
> >                 at
> > org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.ja
> > va:103)
> >
> >                 at
> > org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:9
> > 50)
> >
> >                 at
> > org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValv
> > e.java:116)
> >
> >                 at
> > org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java
> > :421)
> >
> >                 at
> > org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp1
> > 1Processor.java:1070)
> >
> >                 at
> > org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(A
> > bstractProtocol.java:611)
> >
> >                 at
> > org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint
> > .java:316)
> >
> >                 at
> > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.j
> > ava:1145)
> >
> >                 at
> > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.
> > java:615)
> >
> >                 at
> > org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThr
> > ead.java:61)
> >
> >                 at java.lang.Thread.run(Thread.java:745)
> >
> > Caused by: java.lang.NullPointerException
> >
> >                 at
> > sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:524)
> >
> >                 at
> > sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:493)
> >
> >                 at
> > sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
> >
> >                 at
> > java.sql.DriverManager.getDriver(DriverManager.java:262)
> >
> >                 at
> > org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(Ba
> > sicDataSource.java:1437)
> >
> >                 ... 25 more
> >
> > --------------------
> >
> >
> >
> > Environment :
> >
> > Win 7
> >
> > Java - jdk 1.7.0.65
> >
> > Tomcat - 7.0.57
> >
> > MySQL - 5.1.18
> >
> >
> >
> > --------------------
> >
> >
> >
> > Tomcat service properties:
> >
> > -Dcatalina.home=Y:\Programs\Tomcat\Tomcat7
> >
> > -Dcatalina.base=Y:\00-Prod\data\catalina
> >
> > -Djava.endorsed.dirs=Y:\Programs\Tomcat\Tomcat7\endorsed
> >
> > -Djava.io.tmpdir=Y:\Programs\Tomcat\Tomcat7\temp
> >
> > -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
> >
> >
> > -Djava.util.logging.config.file=Y:\Programs\Tomcat\Tomcat7\conf\loggin
> > g.properties
> >
> > -Dcom.sun.management.jmxremote
> >
> > -Dcom.sun.management.jmxremote.port=8099
> >
> > -Dcom.sun.management.jmxremote.ssl=false
> >
> > -Dcom.sun.management.jmxremote.authenticate=false
> >
> > -XX:MaxPermSize=512m
> >
> >
> >
> > --------------------
> >
> >
> >
> > CATALINA_HOME/lib contents
> >
> > …
> >
> > tomcat-dbcp.jar
> >
> > tomcat-jdbc.jar
> >
> > …
> >
> >
> >
> > --------------------
> >
> >
> >
> > CATALINA_BASE/lib contents:
> >
> > mysql-connector-java-5.1.18-bin.jar
> >
> > --------------------
> >
> >
> >
> > CATALINA_BASE/conf/server.xml
> >
> > ...
> >
> > …
> >
> >   <GlobalNamingResources>
> >
> >                                …
> >
>
> What else do you have defined in this block?
>
>
> >  -->
> >
> >                 <Resource          name="sharedDataSource"
> >
> >                                                global="sharedDataSource"
> >
>
> Not sure about this "global" attribute.  I don't believe it's an attribute
> of the pool.  Why did you add it?
>
>
> >                                                 auth="Container"
> >
> >
> type="javax.sql.DataSource"
> >
> >
> > factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
> >
> >
> > driverClassName="com.mysql.jdbc.Driver"
> >
> >                                                initialSize="2"
> >
>
> You have initialSize set to 2.  This should attempt to make connections
> when you start Tomcat.  Do you see any errors at that time?
>
>
> > minIdle="4" maxActive="8" maxIdle="4" maxWait="10000"
> >
> >                                                username="javauser"
> > password="javadude"
> >
> >
> > url="jdbc:mysql://localhost:3306/javatest"/>
> >
> >
> >
> >   </GlobalNamingResources>
> >
> >
> >
> > …
> >
> > ...
> >
> > --------------------
> >
> >
> >
> > CATALINA_BASE/conf/Catalina/localhost/test-app.xml
> >
> >
> >
> >
> >
> > <?xml version='1.0' encoding='utf-8'?>
> >
> > <Context path="/test-app" privileged="true">
> >
>
> This is unrelated, but don't set "path" here.  The path attribute is
> ignore here.  The path is determined by the name of the xml file, which
> just happens to be "test-app" as well.
>
> Also what else do you have define in this file?
>
>
> >                  ...
> >
> >                 ...
> >
> >     <!-- url: The JDBC connection url for connecting to your MySQL
> > database. -->
> >
> >                 <ResourceLink  name="jdbc/LocalTestDB"
> >
> >                                                global="sharedDataSource"
> >
> >
> > type="javax.sql.DataSource"/>
> >
> >
> >
> >                 ...
> >
> >                 ...
> >
> > </Context>
> >
> > --------------------
> >
>
> Do you have anything set in "conf/context.xml" or in your web.xml?
>
> Dan
>
>
> >
> >
> > DBTest.java excerpt :
> >
> >
> >
> > package testPackage;
> >
> >
> >
> > import javax.servlet.*;
> >
> > import javax.servlet.annotation.WebServlet;
> >
> > import javax.servlet.http.*;
> >
> > import javax.naming.Context;
> >
> > import javax.naming.InitialContext;
> >
> > import javax.naming.NamingException;
> >
> > import javax.sql.DataSource;
> >
> >
> >
> > import java.sql.Connection;
> >
> > import java.sql.ResultSet;
> >
> > import java.sql.SQLException;
> >
> > import java.sql.Statement;
> >
> > ....
> >
> >
> >
> > @WebServlet(name="DBTest", urlPatterns="/DatabaseTest")
> >
> > public class DBTest extends HttpServlet {
> >
> >
> >
> >                 protected void doGet(HttpServletRequest request,
> > HttpServletResponse response) throws ServletException, IOException {
> >
> >                                // TODO Auto-generated method stub
> >
> >
> >
> >                     PrintWriter out = response.getWriter();
> >
> >
> >
> >                                DataSource ds;
> >
> >                                Connection con;
> >
> >                                con = null;
> >
> >
> >
> >                                String title = "Database Result";
> >
> >                                ...
> >
> >                                ...
> >
> >                                try {
> >
> >
> >
> >                                                Context ctx = new
> > InitialContext();
> >
> >                                                Context initContext  =
> > (Context) ctx.lookup("java:/comp/env");
> >
> >                                                ds = (DataSource)
> > initContext.lookup("jdbc/TestDB");
> >
> >
> >
> > <!-- line 62 --> con = ds.getConnection();
> >
> >                                ...
> >
> >                                ...
> >
> >
> >
> > --------------------
> >
> >
> >
> > Note that when I don’t share the datasource (Resource element is in
> > test-app.xml and no ResourceLink in server.xml), it works fine.
> >
> >
> >
> > Any ideas on where should I look at ?
> >
> >
> >
> > Best Regards
> >
> > [image: blue_strip]
> >
> >
> >
> > Jean-Louis Matéo
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

RE: Issue when using tomcat JDBC Connection Pool with a shared resource

Posted by Jean-Louis Mateo <je...@bull.net>.
Hi Dan,

Thank you for having replied to this issue.
First of all, now it works fine but I would like to answer your questions...

> Not sure about this "global" attribute.  I don't believe it's an attribute of the pool.  Why did you add it?
	That's what I've read here http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Resource_Definitions

> 2.) It has no url or driver set.
	Thanks. The issue was here and  I should have read it more closely about the "name" property (at the same above url):
		"name: The name of the resource link to be created, relative to the java:comp/env context."
		So...
		Before, in my context file
		<ResourceLink  name="jdbc/LocalTestDB" <-------- E R R O R  this jndi name doesn't exist
                        	global="sharedDataSource"
		type="javax.sql.DataSource"/>

		After, in my context file
		<ResourceLink	name="jdbc/TestDB" <----- That's the right name
		global="sharedDataSource"
		type="javax.sql.DataSource"/>

		Now it works fine

	Note: In a way, you were right "global" property is no need in <GlobalNamingResources> (server.xml)
		Only "global" (from context.xml, ResourceLink) and "name" (from server.xml, <GlobalNamingResources-Resource>) are needed and have to match

> You have initialSize set to 2.  This should attempt to make connections when you start Tomcat.  Do you see any errors at that time?
	There were no errors. At launching time, the pool is well created with 2 connexions in LISTENING state (netstat -an)

> This is unrelated, but don't set "path" here.  The path attribute is ignore here.  The path is determined by the name of the xml file, which just happens to be "test-app" as well.
	OK. "path" is no longer set.

> Do you have anything set in "conf/context.xml" or in your web.xml?
	See the attached file


Best Regards

Jean-Louis Matéo


-----Message d'origine-----
De : Daniel Mikusa [mailto:dmikusa@pivotal.io] 
Envoyé : vendredi 6 février 2015 14:06
À : Tomcat Users List
Objet : Re: Issue when using tomcat JDBC Connection Pool with a shared resource

On Fri, Feb 6, 2015 at 6:27 AM, Jean-Louis Mateo <je...@bull.net>
wrote:

>  Hi,
>
>
>
> I would like to use the Tomcat JDBC Connection Pool with a shared 
> resource so I’ve read :
>
>  http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html#Standalone and 
> http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Resource_L
> inks
>
>
>
> …. and tried to do the same but when I try to access to my servlet I 
> get the following message:
>
>
>
> org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC 
> driver of class '' for connect URL 'null'
>

A couple odd things here...

1.) It's trying to use DBCP, not the jdbc connection pool.
2.) It has no url or driver set.


>                  at
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(Ba
> sicDataSource.java:1452)
>
>                 at
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicData
> Source.java:1371)
>
>                 at
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSou
> rce.java:1044)
>
>                 at testPackage.DBTest.doGet(DBTest.java:62)
>
>                 at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
>
>                 at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
>
>                 at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appli
> cationFilterChain.java:303)
>
>                 at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFi
> lterChain.java:208)
>
>                 at
> org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
>
>                 at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appli
> cationFilterChain.java:241)
>
>                 at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFi
> lterChain.java:208)
>
>                 at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperVa
> lve.java:220)
>
>                 at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextVa
> lve.java:122)
>
>                 at
> org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authenticat
> orBase.java:612)
>
>                 at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.ja
> va:170)
>
>                 at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.ja
> va:103)
>
>                 at
> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:9
> 50)
>
>                 at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValv
> e.java:116)
>
>                 at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java
> :421)
>
>                 at
> org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp1
> 1Processor.java:1070)
>
>                 at
> org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(A
> bstractProtocol.java:611)
>
>                 at
> org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint
> .java:316)
>
>                 at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.j
> ava:1145)
>
>                 at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.
> java:615)
>
>                 at
> org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThr
> ead.java:61)
>
>                 at java.lang.Thread.run(Thread.java:745)
>
> Caused by: java.lang.NullPointerException
>
>                 at
> sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:524)
>
>                 at
> sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:493)
>
>                 at
> sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
>
>                 at 
> java.sql.DriverManager.getDriver(DriverManager.java:262)
>
>                 at
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(Ba
> sicDataSource.java:1437)
>
>                 ... 25 more
>
> --------------------
>
>
>
> Environment :
>
> Win 7
>
> Java - jdk 1.7.0.65
>
> Tomcat - 7.0.57
>
> MySQL - 5.1.18
>
>
>
> --------------------
>
>
>
> Tomcat service properties:
>
> -Dcatalina.home=Y:\Programs\Tomcat\Tomcat7
>
> -Dcatalina.base=Y:\00-Prod\data\catalina
>
> -Djava.endorsed.dirs=Y:\Programs\Tomcat\Tomcat7\endorsed
>
> -Djava.io.tmpdir=Y:\Programs\Tomcat\Tomcat7\temp
>
> -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
>
>
> -Djava.util.logging.config.file=Y:\Programs\Tomcat\Tomcat7\conf\loggin
> g.properties
>
> -Dcom.sun.management.jmxremote
>
> -Dcom.sun.management.jmxremote.port=8099
>
> -Dcom.sun.management.jmxremote.ssl=false
>
> -Dcom.sun.management.jmxremote.authenticate=false
>
> -XX:MaxPermSize=512m
>
>
>
> --------------------
>
>
>
> CATALINA_HOME/lib contents
>
> …
>
> tomcat-dbcp.jar
>
> tomcat-jdbc.jar
>
> …
>
>
>
> --------------------
>
>
>
> CATALINA_BASE/lib contents:
>
> mysql-connector-java-5.1.18-bin.jar
>
> --------------------
>
>
>
> CATALINA_BASE/conf/server.xml
>
> ...
>
> …
>
>   <GlobalNamingResources>
>
>                                …
>

What else do you have defined in this block?


>  -->
>
>                 <Resource          name="sharedDataSource"
>
>                                                global="sharedDataSource"
>

Not sure about this "global" attribute.  I don't believe it's an attribute of the pool.  Why did you add it?


>                                                 auth="Container"
>
>                                                type="javax.sql.DataSource"
>
>
> factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
>
>
> driverClassName="com.mysql.jdbc.Driver"
>
>                                                initialSize="2"
>

You have initialSize set to 2.  This should attempt to make connections when you start Tomcat.  Do you see any errors at that time?


> minIdle="4" maxActive="8" maxIdle="4" maxWait="10000"
>
>                                                username="javauser"
> password="javadude"
>
>
> url="jdbc:mysql://localhost:3306/javatest"/>
>
>
>
>   </GlobalNamingResources>
>
>
>
> …
>
> ...
>
> --------------------
>
>
>
> CATALINA_BASE/conf/Catalina/localhost/test-app.xml
>
>
>
>
>
> <?xml version='1.0' encoding='utf-8'?>
>
> <Context path="/test-app" privileged="true">
>

This is unrelated, but don't set "path" here.  The path attribute is ignore here.  The path is determined by the name of the xml file, which just happens to be "test-app" as well.

Also what else do you have define in this file?


>                  ...
>
>                 ...
>
>     <!-- url: The JDBC connection url for connecting to your MySQL 
> database. -->
>
>                 <ResourceLink  name="jdbc/LocalTestDB"
>
>                                                global="sharedDataSource"
>
>
> type="javax.sql.DataSource"/>
>
>
>
>                 ...
>
>                 ...
>
> </Context>
>
> --------------------
>

Do you have anything set in "conf/context.xml" or in your web.xml?

Dan


>
>
> DBTest.java excerpt :
>
>
>
> package testPackage;
>
>
>
> import javax.servlet.*;
>
> import javax.servlet.annotation.WebServlet;
>
> import javax.servlet.http.*;
>
> import javax.naming.Context;
>
> import javax.naming.InitialContext;
>
> import javax.naming.NamingException;
>
> import javax.sql.DataSource;
>
>
>
> import java.sql.Connection;
>
> import java.sql.ResultSet;
>
> import java.sql.SQLException;
>
> import java.sql.Statement;
>
> ....
>
>
>
> @WebServlet(name="DBTest", urlPatterns="/DatabaseTest")
>
> public class DBTest extends HttpServlet {
>
>
>
>                 protected void doGet(HttpServletRequest request, 
> HttpServletResponse response) throws ServletException, IOException {
>
>                                // TODO Auto-generated method stub
>
>
>
>                     PrintWriter out = response.getWriter();
>
>
>
>                                DataSource ds;
>
>                                Connection con;
>
>                                con = null;
>
>
>
>                                String title = "Database Result";
>
>                                ...
>
>                                ...
>
>                                try {
>
>
>
>                                                Context ctx = new 
> InitialContext();
>
>                                                Context initContext  =
> (Context) ctx.lookup("java:/comp/env");
>
>                                                ds = (DataSource) 
> initContext.lookup("jdbc/TestDB");
>
>
>
> <!-- line 62 --> con = ds.getConnection();
>
>                                ...
>
>                                ...
>
>
>
> --------------------
>
>
>
> Note that when I don’t share the datasource (Resource element is in 
> test-app.xml and no ResourceLink in server.xml), it works fine.
>
>
>
> Any ideas on where should I look at ?
>
>
>
> Best Regards
>
> [image: blue_strip]
>
>
>
> Jean-Louis Matéo
>

Re: Issue when using tomcat JDBC Connection Pool with a shared resource

Posted by Daniel Mikusa <dm...@pivotal.io>.
On Fri, Feb 6, 2015 at 6:27 AM, Jean-Louis Mateo <je...@bull.net>
wrote:

>  Hi,
>
>
>
> I would like to use the Tomcat JDBC Connection Pool with a shared resource
> so I’ve read :
>
>  http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html#Standalone and
> http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Resource_Links
>
>
>
> …. and tried to do the same but when I try to access to my servlet I get
> the following message:
>
>
>
> org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver
> of class '' for connect URL 'null'
>

A couple odd things here...

1.) It's trying to use DBCP, not the jdbc connection pool.
2.) It has no url or driver set.


>                  at
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
>
>                 at
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
>
>                 at
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
>
>                 at testPackage.DBTest.doGet(DBTest.java:62)
>
>                 at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
>
>                 at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
>
>                 at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
>
>                 at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
>
>                 at
> org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
>
>                 at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
>
>                 at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
>
>                 at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
>
>                 at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
>
>                 at
> org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:612)
>
>                 at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
>
>                 at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
>
>                 at
> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
>
>                 at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
>
>                 at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
>
>                 at
> org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
>
>                 at
> org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
>
>                 at
> org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
>
>                 at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
>
>                 at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
>
>                 at
> org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
>
>                 at java.lang.Thread.run(Thread.java:745)
>
> Caused by: java.lang.NullPointerException
>
>                 at
> sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:524)
>
>                 at
> sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:493)
>
>                 at
> sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
>
>                 at java.sql.DriverManager.getDriver(DriverManager.java:262)
>
>                 at
> org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
>
>                 ... 25 more
>
> --------------------
>
>
>
> Environment :
>
> Win 7
>
> Java - jdk 1.7.0.65
>
> Tomcat - 7.0.57
>
> MySQL - 5.1.18
>
>
>
> --------------------
>
>
>
> Tomcat service properties:
>
> -Dcatalina.home=Y:\Programs\Tomcat\Tomcat7
>
> -Dcatalina.base=Y:\00-Prod\data\catalina
>
> -Djava.endorsed.dirs=Y:\Programs\Tomcat\Tomcat7\endorsed
>
> -Djava.io.tmpdir=Y:\Programs\Tomcat\Tomcat7\temp
>
> -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
>
>
> -Djava.util.logging.config.file=Y:\Programs\Tomcat\Tomcat7\conf\logging.properties
>
> -Dcom.sun.management.jmxremote
>
> -Dcom.sun.management.jmxremote.port=8099
>
> -Dcom.sun.management.jmxremote.ssl=false
>
> -Dcom.sun.management.jmxremote.authenticate=false
>
> -XX:MaxPermSize=512m
>
>
>
> --------------------
>
>
>
> CATALINA_HOME/lib contents
>
> …
>
> tomcat-dbcp.jar
>
> tomcat-jdbc.jar
>
> …
>
>
>
> --------------------
>
>
>
> CATALINA_BASE/lib contents:
>
> mysql-connector-java-5.1.18-bin.jar
>
> --------------------
>
>
>
> CATALINA_BASE/conf/server.xml
>
> ...
>
> …
>
>   <GlobalNamingResources>
>
>                                …
>

What else do you have defined in this block?


>  -->
>
>                 <Resource          name="sharedDataSource"
>
>                                                global="sharedDataSource"
>

Not sure about this "global" attribute.  I don't believe it's an attribute
of the pool.  Why did you add it?


>                                                 auth="Container"
>
>                                                type="javax.sql.DataSource"
>
>
> factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
>
>
> driverClassName="com.mysql.jdbc.Driver"
>
>                                                initialSize="2"
>

You have initialSize set to 2.  This should attempt to make connections
when you start Tomcat.  Do you see any errors at that time?


> minIdle="4" maxActive="8" maxIdle="4" maxWait="10000"
>
>                                                username="javauser"
> password="javadude"
>
>
> url="jdbc:mysql://localhost:3306/javatest"/>
>
>
>
>   </GlobalNamingResources>
>
>
>
> …
>
> ...
>
> --------------------
>
>
>
> CATALINA_BASE/conf/Catalina/localhost/test-app.xml
>
>
>
>
>
> <?xml version='1.0' encoding='utf-8'?>
>
> <Context path="/test-app" privileged="true">
>

This is unrelated, but don't set "path" here.  The path attribute is ignore
here.  The path is determined by the name of the xml file, which just
happens to be "test-app" as well.

Also what else do you have define in this file?


>                  ...
>
>                 ...
>
>     <!-- url: The JDBC connection url for connecting to your MySQL
> database. -->
>
>                 <ResourceLink  name="jdbc/LocalTestDB"
>
>                                                global="sharedDataSource"
>
>
> type="javax.sql.DataSource"/>
>
>
>
>                 ...
>
>                 ...
>
> </Context>
>
> --------------------
>

Do you have anything set in "conf/context.xml" or in your web.xml?

Dan


>
>
> DBTest.java excerpt :
>
>
>
> package testPackage;
>
>
>
> import javax.servlet.*;
>
> import javax.servlet.annotation.WebServlet;
>
> import javax.servlet.http.*;
>
> import javax.naming.Context;
>
> import javax.naming.InitialContext;
>
> import javax.naming.NamingException;
>
> import javax.sql.DataSource;
>
>
>
> import java.sql.Connection;
>
> import java.sql.ResultSet;
>
> import java.sql.SQLException;
>
> import java.sql.Statement;
>
> ....
>
>
>
> @WebServlet(name="DBTest", urlPatterns="/DatabaseTest")
>
> public class DBTest extends HttpServlet {
>
>
>
>                 protected void doGet(HttpServletRequest request,
> HttpServletResponse response) throws ServletException, IOException {
>
>                                // TODO Auto-generated method stub
>
>
>
>                     PrintWriter out = response.getWriter();
>
>
>
>                                DataSource ds;
>
>                                Connection con;
>
>                                con = null;
>
>
>
>                                String title = "Database Result";
>
>                                ...
>
>                                ...
>
>                                try {
>
>
>
>                                                Context ctx = new
> InitialContext();
>
>                                                Context initContext  =
> (Context) ctx.lookup("java:/comp/env");
>
>                                                ds = (DataSource)
> initContext.lookup("jdbc/TestDB");
>
>
>
> <!-- line 62 --> con = ds.getConnection();
>
>                                ...
>
>                                ...
>
>
>
> --------------------
>
>
>
> Note that when I don’t share the datasource (Resource element is in
> test-app.xml and no ResourceLink in server.xml), it works fine.
>
>
>
> Any ideas on where should I look at ?
>
>
>
> Best Regards
>
> [image: blue_strip]
>
>
>
> Jean-Louis Matéo
>