6 Replies Latest reply on Dec 30, 2014 11:26 AM by Ken Clark

    Newbie use of Data Source

    Ken Clark Newbie

      I am new to WildFly, and am trying to get an application working with a WildFly datasource.

       

      I set up both an XA datasource as well as a regular one, but have been unable to get a very simple Vaadin application to access the database through the data sources so far.

       

      The error I get is:

       

      16:07:16,100 ERROR [stderr] (default task-7) Caused by: java.sql.SQLException: NamingException - Cannot connect to the database. Cause: null

      16:07:16,100 ERROR [stderr] (default task-7) at com.vaadin.data.util.sqlcontainer.connection.J2EEConnectionPool.lookupDataSource(J2EEConnectionPool.java:61)

      16:07:16,100 ERROR [stderr] (default task-7) at com.vaadin.data.util.sqlcontainer.connection.J2EEConnectionPool.getDataSource(J2EEConnectionPool.java:51)

      16:07:16,100 ERROR [stderr] (default task-7) at com.vaadin.data.util.sqlcontainer.connection.J2EEConnectionPool.reserveConnection(J2EEConnectionPool.java:43)

      16:07:16,101 ERROR [stderr] (default task-7) at com.vaadin.data.util.sqlcontainer.query.AbstractTransactionalQuery.getConnection(AbstractTransactionalQuery.java:167)

      16:07:16,101 ERROR [stderr] (default task-7) at com.vaadin.data.util.sqlcontainer.query.TableQuery.fetchMetaData(TableQuery.java:608)

       

      The Vaadin core code seems to be doing just this:

       

          private DataSource lookupDataSource() throws SQLException {

              try {

                  InitialContext e = new InitialContext();

                  return (DataSource)e.lookup(this.dataSourceJndiName);

              } catch (NamingException var2) {

                  throw new SQLException("NamingException - Cannot connect to the database. Cause: " + var2.getMessage());

              }

          }

       

      So it seems to be a pretty straightforward lookup problem.  However, I verified both DS's test connection is successful via the console, and I think I am using the right JNDI name:

       

            ...

            J2EEConnectionPool pool = new J2EEConnectionPool("java:/kankan");

       

            SQLContainer container = null;

            try

            {

               TableQuery tq = new TableQuery("node_types", pool);

               container = new SQLContainer(tq);

            }

       

      I can also see in the log that the Data Source seems to be deploying correctly:

       

      ...

      16:07:12,240 INFO  [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-8) JBAS010417: Started Driver service with driver-name = ojdbc6.jar

      16:07:12,242 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) JBAS010400: Bound data source [java:/kankan]

      16:07:12,253 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-4) JBAS010400: Bound data source [java:jboss/datasources/xads_kankan]

      16:07:12,313 INFO  [org.jboss.as.server] (Controller Boot Thread) JBAS018559: Deployed "ojdbc6.jar" (runtime-name : "ojdbc6.jar")

      ...

       

      The same error occurs regardless of which DS I use.

       

      Any idea what I need to do to fix this?

        • 1. Re: Newbie use of Data Source
          Wolf-Dieter Fink Master

          How your confiiguration look like?

          What if you add the oracle driver as a module?

          • 2. Re: Newbie use of Data Source
            Ken Clark Newbie

            The Oracle driver (ojdbc6.jar) is deployed as a module (see below).

             

            Here is the configuration for the non-XA data source:

             

                            <datasource jta="true" jndi-name="java:/kankan" pool-name="kankan" enabled="true" use-ccm="true">

                                <connection-url>jdbc:oracle:thin:@localhost:1521:xe</connection-url>

                                <driver-class>oracle.jdbc.OracleDriver</driver-class>

                                <driver>ojdbc6.jar</driver>

                                <security>

                                    <user-name>kankan_test</user-name>

                                    <password>xxxxxx</password>

                                </security>

                                <validation>

                                    <validate-on-match>false</validate-on-match>

                                    <background-validation>false</background-validation>

                                </validation>

                                <timeout>

                                    <set-tx-query-timeout>false</set-tx-query-timeout>

                                    <blocking-timeout-millis>0</blocking-timeout-millis>

                                    <idle-timeout-minutes>0</idle-timeout-minutes>

                                    <query-timeout>0</query-timeout>

                                    <use-try-lock>0</use-try-lock>

                                    <allocation-retry>0</allocation-retry>

                                    <allocation-retry-wait-millis>0</allocation-retry-wait-millis>

                                </timeout>

                                <statement>

                                    <share-prepared-statements>false</share-prepared-statements>

                                </statement>

                            </datasource>

             

            And here is the driver configuration:

             

                <deployments>

                    <deployment name="ojdbc6.jar" runtime-name="ojdbc6.jar">

                        <content sha1="a483a01111e2f404d864a6111109dc0e1be3fe6c"/>

                    </deployment>

                </deployments>

            • 3. Re: Newbie use of Data Source
              jaikiran pai Master

              catch (NamingException var2) {

                          throw new SQLException("NamingException - Cannot connect to the database. Cause: " + var2.getMessage());

                      }

              Change that to:

               

              catch (NamingException var2) {

                          throw new SQLException("NamingException - Cannot connect to the database. Cause: " + var2.getMessage(), var2);

                      }

               

              and post the new entire exception stacktrace.

              • 4. Re: Newbie use of Data Source
                Ken Clark Newbie

                09:05:20,243 ERROR [stderr] (default task-7) java.lang.RuntimeException: java.sql.SQLException: NamingException - Cannot connect to the database. Cause: null

                09:05:20,243 ERROR [stderr] (default task-7) at com.vaadin.data.util.sqlcontainer.query.TableQuery.fetchMetaData(TableQuery.java:659)

                09:05:20,244 ERROR [stderr] (default task-7) at com.vaadin.data.util.sqlcontainer.query.TableQuery.<init>(TableQuery.java:189)

                09:05:20,244 ERROR [stderr] (default task-7) at com.vaadin.data.util.sqlcontainer.query.TableQuery.<init>(TableQuery.java:127)

                09:05:20,244 ERROR [stderr] (default task-7) at com.vaadin.data.util.sqlcontainer.query.TableQuery.<init>(TableQuery.java:105)

                09:05:20,247 ERROR [stderr] (default task-7) at com.vaadin.data.util.sqlcontainer.query.TableQuery.<init>(TableQuery.java:147)

                09:05:20,247 ERROR [stderr] (default task-7) at com.kankan.ui.StartApp.init(StartApp.java:30)

                09:05:20,247 ERROR [stderr] (default task-7) at com.vaadin.ui.UI.doInit(UI.java:641)

                09:05:20,247 ERROR [stderr] (default task-7) at com.vaadin.server.communication.UIInitHandler.getBrowserDetailsUI(UIInitHandler.java:217)

                09:05:20,247 ERROR [stderr] (default task-7) at com.vaadin.server.communication.UIInitHandler.synchronizedHandleRequest(UIInitHandler.java:74)

                09:05:20,247 ERROR [stderr] (default task-7) at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)

                09:05:20,248 ERROR [stderr] (default task-7) at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1406)

                09:05:20,248 ERROR [stderr] (default task-7) at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:305)

                09:05:20,248 ERROR [stderr] (default task-7) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)

                09:05:20,250 ERROR [stderr] (default task-7) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)

                09:05:20,250 ERROR [stderr] (default task-7) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)

                09:05:20,251 ERROR [stderr] (default task-7) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)

                09:05:20,251 ERROR [stderr] (default task-7) at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)

                09:05:20,251 ERROR [stderr] (default task-7) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

                09:05:20,251 ERROR [stderr] (default task-7) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)

                09:05:20,251 ERROR [stderr] (default task-7) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56)

                09:05:20,251 ERROR [stderr] (default task-7) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

                09:05:20,251 ERROR [stderr] (default task-7) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45)

                09:05:20,251 ERROR [stderr] (default task-7) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:63)

                09:05:20,252 ERROR [stderr] (default task-7) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)

                09:05:20,252 ERROR [stderr] (default task-7) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70)

                09:05:20,252 ERROR [stderr] (default task-7) at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)

                09:05:20,253 ERROR [stderr] (default task-7) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

                09:05:20,253 ERROR [stderr] (default task-7) at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)

                09:05:20,253 ERROR [stderr] (default task-7) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

                09:05:20,254 ERROR [stderr] (default task-7) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)

                09:05:20,254 ERROR [stderr] (default task-7) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261)

                09:05:20,254 ERROR [stderr] (default task-7) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:247)

                09:05:20,254 ERROR [stderr] (default task-7) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:76)

                09:05:20,254 ERROR [stderr] (default task-7) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:166)

                09:05:20,254 ERROR [stderr] (default task-7) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:197)

                09:05:20,255 ERROR [stderr] (default task-7) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:759)

                09:05:20,255 ERROR [stderr] (default task-7) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

                09:05:20,256 ERROR [stderr] (default task-7) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

                09:05:20,256 ERROR [stderr] (default task-7) at java.lang.Thread.run(Thread.java:745)

                09:05:20,257 ERROR [stderr] (default task-7) Caused by: java.sql.SQLException: NamingException - Cannot connect to the database. Cause: null

                09:05:20,259 ERROR [stderr] (default task-7) at com.vaadin.data.util.sqlcontainer.connection.J2EEConnectionPool.lookupDataSource(J2EEConnectionPool.java:63)

                09:05:20,259 ERROR [stderr] (default task-7) at com.vaadin.data.util.sqlcontainer.connection.J2EEConnectionPool.getDataSource(J2EEConnectionPool.java:51)

                09:05:20,259 ERROR [stderr] (default task-7) at com.vaadin.data.util.sqlcontainer.connection.J2EEConnectionPool.reserveConnection(J2EEConnectionPool.java:43)

                09:05:20,260 ERROR [stderr] (default task-7) at com.vaadin.data.util.sqlcontainer.query.AbstractTransactionalQuery.getConnection(AbstractTransactionalQuery.java:167)

                09:05:20,260 ERROR [stderr] (default task-7) at com.vaadin.data.util.sqlcontainer.query.TableQuery.fetchMetaData(TableQuery.java:608)

                09:05:20,260 ERROR [stderr] (default task-7) ... 38 more

                09:05:20,260 ERROR [stderr] (default task-7) Caused by: javax.naming.NameNotFoundException; remaining name 'java:/kankan'

                09:05:20,260 ERROR [stderr] (default task-7) at org.eclipse.jetty.jndi.local.localContextRoot.lookup(localContextRoot.java:490)

                09:05:20,260 ERROR [stderr] (default task-7) at org.eclipse.jetty.jndi.local.localContextRoot.lookup(localContextRoot.java:536)

                09:05:20,260 ERROR [stderr] (default task-7) at javax.naming.InitialContext.lookup(InitialContext.java:417)

                09:05:20,260 ERROR [stderr] (default task-7) at javax.naming.InitialContext.lookup(InitialContext.java:417)

                09:05:20,261 ERROR [stderr] (default task-7) at com.vaadin.data.util.sqlcontainer.connection.J2EEConnectionPool.lookupDataSource(J2EEConnectionPool.java:59)

                09:05:20,261 ERROR [stderr] (default task-7) ... 42 more

                • 5. Re: Newbie use of Data Source
                  jaikiran pai Master

                  09:05:20,260 ERROR [stderr] (default task-7) Caused by: javax.naming.NameNotFoundException; remaining name 'java:/kankan'

                  09:05:20,260 ERROR [stderr] (default task-7) at org.eclipse.jetty.jndi.local.localContextRoot.lookup(localContextRoot.java:490)

                  09:05:20,260 ERROR [stderr] (default task-7) at org.eclipse.jetty.jndi.local.localContextRoot.lookup(localContextRoot.java:536)

                  It looks like your application contains a jar (or more than one) which contains those Eclipse Jetty classes of JNDI and those are incorrectly being picked up for that lookup. You'll have to exclude those jars from the deployed application packaging.

                  • 6. Re: Newbie use of Data Source
                    Ken Clark Newbie

                    The Vaadin full distribution (at least the current one, 7.3.7) contains a number of jetty jars, including a JNDI one.

                     

                    Perhaps these are needed to provide some container services when using Tomcat or something like that, but are probably counterproductive for Vaadin deployments to an application server like JBoss (I am speculating).

                     

                    At any rate, I removed the jetty jndi jar and this problem went away.

                     

                    Thanks all for your help!

                    1 of 1 people found this helpful