Installing a Datasource on JBoss AS 7 and WildFly as module can be tedious as it requires three commands to complete. However by creating a batch script you can easily automate the process and install it on every distribution with as little as a shell command. Here is a sample script to create a Datasource to be used for a MySQL database:



module add --name=com.mysql --resources=/home/jboss/Downloads/mysql-connector-java-5.1.24-bin.jar --dependencies=javax.api,javax.transaction.api

data-source add --jndi-name=java:/jboss/MySQLDS --name=MySQLPool --connection-url=jdbc:mysql://localhost:3306/as7development --driver-name=mysql --user-name=jboss --password=jboss


As you can see, a batch script needs just a batch command to start the batch process and the run-batch command to execute the list of commands. the only thing you have to customize are the Datasource settings and the location where your JDBC Driver is to be found (We have assumed it's on /home/jboss/Downloads)

Save the above script in a file, let's say dbscrpit.cli and execute it with:

./ --file=dbscript.cli 


if you fail to activate the Datasource due to the following error:

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Access denied for user 'jboss'@'localhost' to database 'as7development'
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.7.0_67]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance( [rt.jar:1.7.0_67]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance( [rt.jar:1.7.0_67]
    at java.lang.reflect.Constructor.newInstance( [rt.jar:1.7.0_67]
    at com.mysql.jdbc.Util.handleNewInstance(
    at com.mysql.jdbc.Util.getInstance(

It's a problem with your user settings. You should check out that your user has been granted privileges to connect to the specified host.

Make sure you have granted privileges to your user, for example:

CREATE USER 'jboss'@'localhost' IDENTIFIED BY 'jboss';

GRANT ALL PRIVILEGES ON *.* to 'jboss'@'localhost' with GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

Related articles available on

How to deploy a DataSource in jboss at application level ?

  Do you need to deploy your DataSource along with your Enterpri

JBoss Datasource HA

This tutorial has been updated for the new release of JBoss Appli

JBoss run out of Connections ?

Have you got No ManagedConnections available error message ? well

How to connect to a DataSource from a remote client?

  If you want to connect to your JBoss Connection Pool from a re

WildFly Datasource configuration

A Datasource is a Java Naming and Directory Interface (JNDI) obje

How do I get the list of Datasources available ?

JBOSS AS 4/5 Users You can use either twiddle: $ que