Home > Articles > Programming > Java

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

Adding Another Datasource

To add another datasource to a JBoss configuration, you create a new configuration file. I want to create a datasource that will connect to my locally hosted MySQL database and specifically use the example database. To do this, I create another configuration file similar to the one shown earlier:

<?xml version="1.0" encoding="UTF-8"?>
<datasources>
 <local-tx-datasource>
  <jndi-name>ExampleDS</jndi-name>
   <connection-url>jdbc:mysql://localhost/example</connection-url>
   <driver-class>org.gjt.mm.mysql.Driver</driver-class>
   <user-name>exampleUser</user-name>
   <password>examplePassword</password>
   <min-pool-size>5</min-pool-size>
   <max-pool-size>20</max-pool-size>
   <idle-timeout-minutes>0</idle-timeout-minutes>
   <track-statements/>
 </local-tx-datasource>
</datasources>

Here I create a datasource named ExampleDS that connects to a MySQL database via JDBC, using the username exampleUser and the password examplePassword. I've specified that the connection pool will have a minimum of 5 connections but not more than 20, and that these connections will never go idle. I then save this file in the deploy directory as example-ds.xml. (The filename isn't important, but it's helpful to be consistent.)

Because my new datasource doesn't need or depend on any other modules, there's no <depends> tag. And because I'm specifying the username and password for the database in this file, I don't need to reference a security domain.

  • + Share This
  • 🔖 Save To Your Account