Robin Jonsson
Robin Jonsson

Reputation: 2851

TomEE DataSource isn't found

I have a strange problem regarding TomEE and using a DataSource specified in tomee.xml. It might be worth noting that I'm using Netbeans, TomEE and MySQL. Running on Ubuntu 13.04 (Xubuntu latest)

The tomee.xml file is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<tomee>
    <Resource id="booktablesDS" type="DataSource">
        JdbcDriver com.mysql.jdbc.Driver
        JdbcUrl jdbc:mysql:localhost:3306/book_tables
        UserName juser
        Password jpassword
        JtaManaged true
    </Resource>
</tomee>

And a small codesnippet, testing the connection pool:

@Resource DataSource booktablesDS;

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {

    Connection c = booktablesDS.getConnection();
    Statement stmt = c.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT * FROM BOOKS");

The output I'm getting from TomEE is:

SEVERE: null
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'

Full stacktrace follows.

May 06, 2013 11:08:53 AM org.apache.catalina.util.LifecycleBase start
INFO: The start() method was called on component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/EJBTest]] after start() had already been called. The second call will be ignored.
May 06, 2013 11:08:54 AM MainS processRequest
SEVERE: null
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 MainS.processRequest(MainS.java:35)
    at MainS.doGet(MainS.java:64)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)
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:273)
    at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
    ... 22 more

May 06, 2013 11:08:55 AM org.apache.catalina.startup.HostConfig deleteRedeployResources
INFO: Undeploying context [/EJBTest]

Basicly it feels like netbeans is deploying the project with another tomee.xml file? Disregarding the values in my tomee.xml, which is under tom-ee/conf/tomee.xml

Help would be awesome.

Upvotes: 2

Views: 2187

Answers (2)

moskito-x
moskito-x

Reputation: 11958

Looks like your url is wrong.

jdbc:mysql:localhost:3306/book_tables

should be

jdbc:mysql://localhost:3306/book_tables

Can you double-check whether the MySQL driver JAR is really there in tomee/lib folder.

Upvotes: 5

Eugene
Eugene

Reputation: 530

Try to change your code like this:

@Resource(name = "booktablesDS", type = javax.sql.DataSource.class)
DataSource booktablesDS;

Upvotes: 2

Related Questions