Setting Up a Connection Pool on the JBoss Application Server

See Also

A JDBC connection pool is a group of reusable connections that a web server or application server maintains for a particular database. Applications requesting a connection to a database obtain that connection from the pool. When an application closes a connection, the connection is returned to the pool. Connection pool properties may vary with different database vendors. Some common properties are the URL for the database name, user name, and password.

The first step in creating a database connection pool on the JBoss Application Server is to create JDBC resource (also called a data source). A JDBC resource provides applications with a connection to a database. Typically, there is at least one JDBC resource for each database accessed by an application deployed in a domain. It is possible to have more than one JDBC resource for a database. You can create a JDBC resource manually in a file tailored to your database server, provided in the JBoss installation directory.

To set up a data source on the JBoss Application Server:

  1. Open the Favorites window (Ctrl-3).
  2. Right-click in the window, choose Add to Favorites, and browse to the JBoss installation directory's docs/examples/jca folder.
  3. Open the -ds.xml file of your choice in the editor. For example, if MySQL is your database server, double-click mysql-ds.xml.
  4. Define the data source. For example, for PointBase, the data source could be similar to the following:
    <datasources>
       <local-tx-datasource>
          <jndi-name>MySqlDS</jndi-name>
          <connection-url>jdbc:mysql://mysql-hostname:3306/jbossdb</connection-url>
          <driver-class>com.mysql.jdbc.Driver</driver-class>
          <user-name>x</user-name>
          <password>y</password>
          <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
          <metadata>
            <type-mapping>mySQL</type-mapping>
          </metadata>
      </local-tx-datasource>
    </datasources>
  5. Copy the file to your JBoss deployment directory. For example, if default is your domain, copy the file to server/default/deploy.

To reference a data source from a web application:

  1. In the WEB-INF/jboss-web.xml file, add a resource reference. For example, for the data source above, the resource reference could be as follows:
    <resource-ref>
      <res-ref-name>MySqlDS</res-ref-name>
      <jndi-name>MySqlDS</jndi-name>
    </resource-ref>
  2. In the WEB-INF/web.xml file, add a resource reference. For example, for the data source above, the resource reference could be as follows:
    <resource-ref>
      <res-ref-name>MySqlDS</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>

To prepare to use a data source on the JBoss Application Server:

  1. Register the JBoss Application Server.
  2. Set the JBoss port number in its server.xml file. By default, the port number is 8080. If you are using the default domain, the server.xml file is found here:
    \server\default\deploy\jbossweb.sar\server.xml
  3. Create a web application and select JBoss Application Server as the target server.
  4. Access the data source in, for example, a JSP page.
See Also
Working with the JBoss Application Server
JBoss Application Server Tasks: Quick Reference

Legal Notices