tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jean-Louis Mateo <jean-louis.ma...@bull.net>
Subject Issue when using tomcat JDBC Connection Pool with a shared resource
Date Fri, 06 Feb 2015 11:27:48 GMT
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

Mime
  • Unnamed multipart/related (inline, None, 0 bytes)
View raw message