How do I get the list of Datasources available ?

A DataSource is the preferred means of getting a connection from a Database. Let’s learn how to fetch the list of Datasources which are configured in the application server using the CLI and programmatically.

WildFly / JBoss EAP 6/7

The simplest way to retrieve the list of Datasources at runtime is using the CLI:

./ --connect --command="/subsystem=datasources:read-resource" | grep "data-source"

On the other hand, if you are running in Domain mode, include the profile name in the CLI command. For example:

./ --connect --command=" /profile=full-ha/subsystem=datasources:read-resource" | grep "data-source"

To fetch the list of Datasources programmatically, you can also use the JMX API. Example:

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class HelloWorld {
	public static void main(String[] args) throws Exception {

	public static void status() throws Exception{
		String host = "localhost";
		int port = 9990;  // management-http port
		String urlString = "service:jmx:remote+http://" + host + ":" + port;
		System.out.println("\n\n\t****  urlString: "+urlString);;
		JMXServiceURL serviceURL = new JMXServiceURL(urlString);

		Map map = new HashMap();
		String[] credentials = new String[] { "admin", "admin" };
		map.put("jmx.remote.credentials", credentials);
		JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, map);

		MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();

                Set instances = connection.queryMBeans(null, null);
                Iterator iterator = instances.iterator();

                while (iterator.hasNext()) {
                  ObjectInstance instance =;
                  if (instance.getObjectName().toString().startsWith(",data-source=") &&
                  System.out.println("Object Name:" + instance.getObjectName());




Please note that you need to include in your application’s classpath the jboss-client JAR files in order to be able to use the remote+http protocol:


JBOSS AS 4/5 Users

You can use the twiddle command line for this purpose:

$ query "jboss.jca:service=DataSourceBinding,*"