Version 6

    Creating a JDBC datasource

     

    The syntax for configuring JCA JDBC connection factories has been simplified in 3.2. Rather than configuring the connection manager factory related MBeans via an mbean services deployment descriptor, an abbreviated datasource centric descriptor is used. This is transformed into the standard jboss-service.xml mbean services deployment descriptor using a XSL transform applied by the org.jboss.deployment.  XSLSubDeployer included in the jboss-jca.sar  deployment. The simplified configuration descriptor is deployed the same as other deployable components. The descriptor must be named using a -ds.xml pattern in order to be recognized by the  XSLSubDeployer. 

     

    The schema for the datasource descriptor is docs/dtd/jboss-ds_1_0.dtd

     

    Examples of datasource descriptors for many popular databases are available in the docs/examples/jca directory. 

     

    To create a datasource:

     

    1. Place the JDBC driver classes in the lib directory of your server.  (server/default/lib, for example)  Jars placed in the lib directory are NOT hot deployable, so you will need to restart JBoss if it is already running.

    2. Copy the most appropriate sample datasource file into your deploy directory.  You can change the name if you like, but the file must end with -ds.xml to be recognized as a datasource descriptor.

    3. Edit the the datasource definition to match your database connection parameters.  The most relevant parameters are:

      • jndi-name: The JNDI name under which the DataSource wrapper will be bound. Note that this  name is relative to the java:/ prefix. The full JNDI name of the DataSource will be java:/jndi-name. DataSource wrappers are bound under the java:/ prefix since they are not usable  outside of the server VM.

      • connection-url: The JDBC driver connection URL string for your driver.   Make sure that the database name, host and port are correct for the database you are trying to connect to.

      • username: This element specifies the default username used when creating a new connection. The  actual username may be overridden by the application code getConnection parameters or the  connection creation context JAAS Subject. 

      • password: This element specifies the default password used when creating a new connection. The  actual password may be overridden by the application code getConnection parameters or the  connection creation context JAAS Subject.

     

    These are the minimal steps to configure a datasource.  Check the server log to see that the datasource was loaded correctly.   You can also DisplayTheJNDITreeWithTheJMXConsole and verify that the datasource is visible under the correct name.

     

    Notes:

    • Multiple datasources can be configured in a single datasource descriptor. 

    • Make sure to use an XA datasource if you need to access multiple databases or other transactional resources in the same transaction. 

    • Consult the JBoss documentation and the DTD for more advanced configuration options.

     

     

    Related:

     

    Referenced by: