5 Replies Latest reply on Jun 5, 2014 2:26 AM by jaikiran

    Error Connecting to Datasource - Wildfly

    gantony

      I have successfully created datasource in wildfly 8. I get an error "javax.naming.CommunicationException: Receive timed out" while trying to connect to the data source.

      Can someone advise?

       

      Thanks.

      Antony.

        • 1. Re: Error Connecting to Datasource - Wildfly
          wdfink

          Could you show a bit more information?

          Also you might use a Java tool like SQuirreL that you are able to test the connection with the same JDBC driver from the same machine

          • 2. Re: Error Connecting to Datasource - Wildfly
            gantony

            Hi Fink,

                     Thanks for your quick response. I have tested connection in Wildfly Data source Administration and the connection was successful. Below is what I use to connect to the data source.

             

                Properties p = new Properties();

                p.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");

                p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");

                p.put(Context.PROVIDER_URL, "jnp://localhost:1099");

                InitialContext ic = new InitialContext(p);

                DataSource ds=(DataSource)ic.lookup("java:jboss/TestDatasource"); 

                Connection con=ds.getConnection();

             

            And this is the error I get.

             

            javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out]

             

            Please advise.

             

            Thanks,

            Antony

            • 3. Re: Error Connecting to Datasource - Wildfly
              jaikiran

              Are you trying to lookup the datasource from a remote client (like standalone application)? If yes, then it's not supported. Furthermore, the jnp: JNDI provider URL too is no longer supported in AS7/EAP6 or WildFly.

              • 4. Re: Error Connecting to Datasource - Wildfly
                gantony

                Hi Jaikiran, Thanks for your reply.

                           I have an ejb deployed in the server in which I have to use Data base connection. And my code to connect to Data source is inside a jar file that is available in the server as well. I have a standalone code to connect to EJB and I am able to connect to the EJB. But when I call the function to connect to Data source I get the error I specified earlier.

                 

                Please advise.

                Antony.

                • 5. Re: Re: Error Connecting to Datasource - Wildfly
                  jaikiran

                  If your code which is trying to lookup the datasource is within the same server as the datasource, then all you need to do is:

                   

                  DataSource ds=(DataSource) InitialContext.doLookup("java:jboss/TestDatasource");  
                      Connection con=ds.getConnection();
                  ....
                  

                   

                  You should get rid of the other lines from the code you posted.