Unlike JBoss AS 6 there is no “$PROFILE/lib” present in JBoss AS 7 where we can place our JDBC Drivers in order to add/register the JDBC Driver. Also in JBoss AS 7 we don’t need to create a separate DataSource file as “*-ds.xml” file.

In JBoss AS 7 the DataSource configuration is placed wither inside the “Jboss-as-7.0.1.Final/standalone/configuration/standalone.xml” (if you are running a JBoss standalone profile), or the datasource information is placed inside the “boss-as-7.0.1.Final/domain/configuration/domain.xml” file.Here in this demonstration we will see how to install/register a JDBC Driver in JBoss AS7 and then how to create a DataSource from Admin-Console.

You can have a look at the below article for creating MySql Datasource
How to create MySql DataSource And Install MySql JDBC Driver in JBoss AS7

There are two options to install/Register a JDBC Driver to JBoss AS 7.
1). Installing a JDBC driver as a deployment
2). Installing a JDBC driver as a module

Installing a JDBC driver as a deployment

First we need to check which Jdbc Driver are we using? Is it a JDBC 4-compliant driver or a Non-JDBC 4 -compliant driver? Any JDBC 4-compliant driver will automatically be recognized and installed into the system by name and version. A JDBC 4-compliant JAR is identified using the Java service provider mechanism. It contains a text a file named “META-INF/services/java.sql.Driver”, which contains the name of the class(es) of the Drivers which exist in that JAR.

If the driver is already JDBC4-comliant then you can directly deploy it inside the “jboss-as-7.0.1.Final/standalone/deployments” based on the mode which you are using to run your JBoss AS.

Dealing with Non JDBC 4 -compliant Drivers:

If your JDBC Driver is NOT JDBC 4-compliant then we can update the driver using “jar” utility by adding the “META-INF/services/java.sql.Driver” inside it. as following:
Step1). Create a directory somewhere in your file system like “/home/userone/testDriver”
Step2). Place your Non-JDBC 4 compliant driver in this directory “/home/userone/testDriver” suppose your Driver Jar name is “YourJdbcDriver.jar”
Step3). Now create “META-INF/services” directory inside “/home/userone/testDriver”
Step4). Create a file with name “java.sql.Driver” inside “/home/userone/testDriver/META-INF/services” directory and then add the fully qualified name of your JDBC Driver class in this file.
Step5). use the jar utility with -u (means update) option to add the META-INF directory with the above contents in it as following

jar  -uf  YourJdbcDriver.jar  META-INF/services/java.sql.Driver

Now you can take your JDBC Driver and then place it inside the “${JBOSS_AS7}/standalone/deployments”.
The advantage of deploying the JDBC Driver as a deployment in “domain” mode is that the deployments are automatically propagated to all servers to which the deployment applies, so the administrator need not to worry about the the JDBC Driver distribution every time.

Installing a JDBC driver as a module

This is another option to install the JDBC Driver as a module. Which requires that we define a new module for our JDBC Driver inside “${JBOSS_AS7}/modules” directory as following:
Suppose if we want to install the Oracle JDBC Driver (ojdbc6.jar) then we will need to do the following steps:
Step1). Create a directory “oracle/jdbc/main” inside the “jboss-as-7.0.1.Final/modules” directory.
Step2). paste your “ojdbc6.jar” oracle Jdbc Driver inside “jboss-as-7.0.1.Final/modules/oracle/jdbc/main” directory.
Step3). Create a file “module.xml” inside “jboss-as-7.0.1.Final/modules/oracle/jdbc/main” as following:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="oracle.jdbc">
        <resource-root path="ojdbc6.jar"/>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>

Step4). Now open your “jboss-as-7.0.1.Final/standalone/configuration/standalone.xml” file or “jboss-as-7.0.1.Final/domain/configuration/domain.xml” file and then add the driver declaration tag refering to your module as following, by default you will see the driver declaration tag already contains the declaration for <driver name=”h2″ module=”com.h2database.h2″>:

                    <driver name="OracleJDBCDriver" module="oracle.jdbc" />
                    <driver name="h2" module="com.h2database.h2">

Here we declared the <driver name=”OracleJDBCDriver” module=”oracle.jdbc”/>

Step5). Create a DataSource in your JBoss AS 7 and then in the Driver section you can refer to this Module name “oracle.jdbc”

Creating a DataSource from JBoss AS 7 Admin Console

Step1). After installing the JDBC Driver as mentioned above start your JBoss AS 7 and then login to the admin-console from URL: “http://localhost:9990/console” (as admin/admin credentials)
Step2). From left hand panel of the console click on “Connectors—>DataSources”

Creating Oracle DataSource in AS7

Step3). In the right side panel you will see a button “Add” click on this button.
Step4). In Wizard “Step 1/3: Datasource Attributes”
Enter the DataSource Name as “OracleDS”
Enter JNDI Name as “java:/OracleDSJNDI” or “java:jboss/OracleDSJNDI” (NOTE the valid DataSource name should start with either java:/ or with java:jboss/ prefix)

DataSource name & JNDI Name

Step5). Now in the next Section “Step 2/3: JDBC Driver” you will see all the installed drivers details. in above case as we already registered oracle driver as a module “OracleJDBCDriver” in previous section so we will be able to see the details as following:

Registered Jdbc Drivers List

Step6). In next section “” provide the Database url (jdbc:oracle:thin:@ ,username and password

Specifying DataSource properties

Step7). you will see following kind of messae in your JBoss AS 7 console output:

DataSource Details

10:50:32,330 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-6) Bound data source [OracleDSJNDI]

For More Details visit:
MiddlewareMagic Team

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.