Pages

Tuesday, June 25, 2013

JBoss 7 : Data Source Snippets

Create a Data Source
We can Create a data Source using jboss-cli.sh utility available in the JBoss Server like

[standalone@localhost:9999 /] data-source add --name=my_pool --driver-name=mysql --connection-url=jdbc:mysql://localhost:3306/test --jndi-name=java:/mysqlDB --user-name=root --password= --use-ccm=false --max-pool-size=25 –blocking-timeout-wait-millis=5000

Once you create the Data Source we need to enable the pool using

[standalone@localhost:9999 /] data-source enable --name=my_pool

But for this we need to make sure the Drivers are available before creating the Data Source

Creating a Driver

we can create a Driver like

[standalone@localhost:9999 /] /subsystem=datasources/jdbc-driver=mysql:add(driver-name=mysql,driver-module-name=com.mysql)
{"outcome" => "success"}

If we need to delete the driver we can use,

[standalone@localhost:9999 /] /subsystem=datasources/jdbc-driver=mysql:remove
{"outcome" => "success"}

Test the Data Source

If we need to test the Data Source we can use,

[standalone@localhost:9999 /] /subsystem=datasources/data-source=my_pool:test-connection-in-pool
{
"outcome" => "success",
"result" => [true]
}

Read statistics of Data sources
If we need various statistics of the Data Source we can use

/subsystem=datasources/data-source=my_pool/statistics=pool:read-resource(include-runtime=true)

Remove a Data Source
In order to remove a data Source we can use

data-source remove –name=my_pool