1 Reply Latest reply on Jul 11, 2016 4:55 AM by Wolf-Dieter Fink

    Problems using JBoss Dev Studio 9.1.0 datasources (configuring and using)

    John P Newbie

      Hi,

       

      I'm new to JBoss. I've spent over a day trying to figure out how to resolve this issue with no luck. I've found various articles/posts about how to use datasources in earlier versions of JBoss but it seems the model has changed with version 9 of JBoss dev studio (which includes JBoss EAP 6.4). Here are the issues I'm facing.

       

      I've configured a data source using the Data Source Explorer tab in dev studio. The data source is operational when I "Test Connection..." from the properties window for the data source. I'm using these settings in the popup window that JBoss dev studio allows us to use to edit the datasource:

      Driver class: com.ibm.db2.jcc.DB2Driver (v4.19)

      Database URL: jdbc:db2://xxx.dev.xxx.us.xxx.com:51490/myDBName

      JNDI URL: java:jboss/datasources/myDS

       

      and I'm able to test the connection successfully. I'm also able to connect to this db using straight JDBC (i.e. DriverManager.getConnection(conn_string,uname,pwd))

       

      But when I try to use this datasource in my java code like this:

      String DATASOURCE_CONTEXT = "java:jboss/datasources/myDS";

      Connection result = null;

      try {

        Context initialContext = new InitialContext();

        if (initialContext == null) {

        log("JNDI problem. Cannot get InitialContext.");

      }

      DataSource datasource = (DataSource) initialContext.lookup(DATASOURCE_CONTEXT);

       

      I get the below error on there line where I do initialContext.lookup():

      "Cannot get connection: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial

      Creating statement...

      java.lang.NullPointerException"

       

      ===========================================

       

      I'm wondering if using the Data Source Explorer to set up a datasource isn't working in this version of JBoss dev studio? If not how should I set it up?

       

      Additionally if I'm able to get this working (or even if I can't)  I will need to create a datasource on the web server. I've seen a few articles about how to do this using -ds files but the model/paradigm seems different now with EAP 6.4

       

      Do I manually go to the folder on disk where the jar would go (for example):

      C:\Users\johnny\jbdevstudio\runtimes\jboss-eap\modules\com\db2\main

      which is where the db2jcc4-10.5.jar file is and create another file there named module.xml and manually edit it to contain something like:

      <module xmlns="urn:jboss:module:1.0" name="com.db2">

         <resources>

           <resource-root path="db2jcc4-10.5.jar"/>

         </resources>

         <dependencies>

            <module name="javax.api"/>

            <module name="javax.transaction.api"/>

          </dependencies>

      </module>

       

      Also the module name I just copied from an online article - what should the module name be?

       

      Once I create this module.xml file - what else do I need to do to allow code running on the web server to access the datasource?

       

      Thanks!