Sunday, January 2, 2011

JBOSS AS 6 : Adding and testing a new Oracle 11g datasource

1 Prerequisites
  • Oracle 11g (R1 or R2 doesn't matter but anyway, I installed the R1)
  • a defined database
  • JBoss AS 6
 2 Adding the new datasource


As described in the JBoss AS documentation, we just need to create and configure a new RDBS-ds.xml file and put it in the jboss-6.0.0.Final\server\your-server-configuration\deploy directory.

In my case, in order to get to the point as quickly as possible (and because I only need a basic datasource configuration at the moment), I created my own oracle-ds.xml file by copying the sample one which is located at : jboss-6.0.0.Final\docs\examples\jca

Here's my own oracle-ds.xml file :

<?xml version="1.0" encoding="UTF-8"?>
<datasources>
    <local-tx-datasource>
        <jndi-name>OracleDS</jndi-name>
        <connection-url>jdbc:oracle:thin:@localhost:1521:CFDB</connection-url>
        <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
        <user-name>CF_USER</user-name>
        <password>mypassword</password>
        <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name>
        <metadata>
            <type-mapping>Oracle11g</type-mapping>
        </metadata>
    </local-tx-datasource>
</datasources>

At this point there's 2 things you should pay attention to :
  • Make sure there's no other xxx-ds.xml file with an identical jndi-name, otherwise, the datasource cannot be deployed correctly.
  • Don't forget to drop the appropriate JDBC driver library in the same directory as the datasource configuration file, that is : jboss-6.0.0.Final\server\your-server-configuration\deploy
3 Testing the connection
1° start the application server
2° log into the server administration console (http://localhost:xxxx/admin-console/login.seam)
3° go to the datasource section as shown below


4° Select the newly created datasource and open the CONTROL tab


5° Click on the Test connection button to run a test
6° As as result, make sure the test ran successfully and that a connection has been obtained


    To check whether a connection has been obtained, especially if you ran several tests, click on the Show 
    details below... button and make sure the result value is Yes


    The result value is critical to test the connection to your datasource because as long as your datasource 
    configuration file is correct, the test could run successfully while your database is not even running, for 
    instance ...

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.