Appendix A. Database Configuration

This appendix describes how to set up database pools for data sources other than the default database embedded in JBoss, Hypersonic SQL. It also shows you how to set up your EJBs to use these database pools. For illustration purposes, we’ve modified Exercise 6.1 to configure and use an Oracle connection pool with JBoss.

Set Up the Database

To deploy a database connection pool, JBoss requires a datapool configuration file. The configuration file is very simple, yet can be used for almost all standard datapool setups.

Basic Setup

The first step is to download the JDBC driver classes for your database. Copy your database’s JDBC JAR file to $JBOSS_HOME/server/default/lib. For example, the Oracle JDBC class files are contained in classes12.zip.

The JBoss distribution includes example database connection-pool files, in the directory $JBOSS_HOME/docs/examples/jca. The name of each file ends in -ds.xml. For this exercise, we’ve copied the oracle-ds.xml configuration file to exAppendixA/titandb-ds.xml and modified it accordingly.

To deploy this connection pool, you must copy titandb-ds.xml to the $JBOSS_HOME/service/default/deploy directory. Note that the name of this config file must end with -ds.xml, or JBoss will not deploy it.

Tip

Database connection pools are among the many things that can be hot-deployed in JBoss, simply by plopping the pool’s XML configuration file into the deploy directory.

Examine some of the configuration parameters this file defines.

titandb-ds.xml

<datasources>
  <local-tx-datasource>
    <jndi-name>OracleDS</jndi-name>

The <jndi-name> tag identifies the connection pool within JNDI. You can look up this pool in JNDI with the java:/OracleDS string. The class of this bound object is javax.sql.DataSource.

    <connection-url
     >jdbc:oracle:thin:@localhost:1521:JBOSSDB</connection-url>

The <connection-url> tag tells the Oracle JDBC driver how to connect to the database. The URL varies depending on the database you use, so consult your database JDBC manuals to find out how to obtain the appropriate address.

    <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>

The <driver-class> tag tells JBoss and the base JDBC classes the name of Oracle’s JDBC driver class they need to instantiate and use.

    <user-name>scott</user-name>
    <password>tiger</password>
  </local-tx-datasource>
</datasources>

Finally, the <user-name> and <password> tags are used when connecting to the Oracle database.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.78.237