2 Replies Latest reply on Mar 20, 2012 4:03 PM by Dale Booth

    JDBC Data Source connection creation - help

    Dale Booth Newbie

      I have successfully got a JNDI data source working in JBoss 7.1.x.  However, when I attempt to set up a JDBC data source connection I run into issues.  I've read through many of the JBoss 7 documentation sites / JBoss dicussions / search sites, but have not found the correct solution. 

       

      I've started with a standalone installation. The datasource section in my standalone.xml file contains the following:

       

      <datasource jta="true" jndi-name="java:jboss/datasources/testDS" pool-name="testDS" enabled="true" use-java-context="true" use-ccm="true">

          <connection-url>jdbc:postgresql://localhost:5432/testDS</connection-url>

          <driver-class>org.postgresql.Driver</driver-class>

          <driver>postgresql-9.1-901.jdbc4.jar</driver>

          <pool>

              <min-pool-size>1</min-pool-size>

              <max-pool-size>20</max-pool-size>

              <prefill>false</prefill>

              <use-strict-min>false</use-strict-min>

          </pool>

          <security>

              <user-name>postgres</user-name>

              <password>postgres</password>

          </security>

          <validation>

              <check-valid-connection-sql>SELECT 1</check-valid-connection-sql>

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

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

          </validation>

          <statement>

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

          </statement>

      </datasource>

      <drivers>

          <driver name="h2" module="com.h2database.h2">

              <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>

          </driver>

          <driver name="postgresql-9.1-901.jdbc4.jar" module="org.postgresql"/>

      </drivers>

       

      NOTE: I found one site that stated that the use-java-context="false" would work, but didn't for me

       

      I have tried using both methods of pushing out the database driver: module AND deployment.  I have gone with the module method.

      I created the appropriate modules directory structure and files.  My module.xml file contains:

       

      <?xml version="1.0" encoding="UTF-8"?>

      <module xmlns="urn:jboss:module:1.0" name="org.postgresql">

          <resources>

              <resource-root path="postgresql-9.1-901.jdbc4.jar"/>

          </resources>

          <dependencies>

              <module name="javax.api"/>

      <!--        <module name="javax.transaction.api"/>  --> <!-- Only necessary on Linux and Mac -->

          </dependencies>

      </module>

       

      In my application I have a jboss-web.xml file which contains:

       

      <?xml version="1.0" encoding="UTF-8" ?>

      <jboss-web>

          <context-root>/test-app</context-root> 

         

          <resource-ref>

              <res-ref-name>jdbc/testDS</res-ref-name>

              <res-type>javax.sql.DataSource</res-type> 

              <jndi-name>java:jboss/datasources/testDS</jndi-name>

          </resource-ref>

      </jboss-web>

       

      When I attempt to change the jndi-name to include jdbc I get a message stating that the jndi-name must start with "java:" OR "java:jboss..."

       

      I have seen references to persistence.xml, but this file doesn't exist in a default JBoss 7.x installation.  I have also seen a could of references to jndi-name="java:jboss/jdbc/yourDS", but JBoss 7 appears to want jndi-name="java:jboss/datasource/yourDS".

       

      What am I missing?  Any help would be appreciated

       

      Thank you

      Dale

        • 1. Re: JDBC Data Source connection creation - help
          jaikiran pai Master

          Dale, welcome to the forums!

           

          It isn't clear what error you are running into and with what configuration. Can you please post the exact configuration(s) and exception stacktrace that you see?

          • 2. Re: JDBC Data Source connection creation - help
            Dale Booth Newbie

            Thank you for your reply.

             

            Regarding your questions:

             

            Configurations:

            The only change I made to the standalone.xml file was with the DS name info "testDS".  The rest of the file was the same.  The other two files were the same as well.

             

            Exception / Stack trace:

            At the time of the post no errors were getting outputted.  I talked with a colleague and we were able to get an error.  ClassNotFoundException for the org.postgresql.Driver.  

             

            Resolved Issue:

            I was able to resolve the JDBC Connection issue by copying the PostgreSQL Driver jar into the ..\WEB-INF\lib directory of the application.

             

             

            FYI...Thanks again,

            Dale