tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <MW...@loftware.com>
Subject RE: Issue when using tomcat JDBC Connection Pool with a shared resource
Date Fri, 06 Feb 2015 14:46:11 GMT


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

Mime
View raw message