Home > Articles > Programming > Java

  • Print
  • + Share This
From the author of

Prerequisites

The example in this article will be deployed into the latest version of JBoss (as of this article)—2.2.1—and will access a table running in SQLServer using the INet Sprinta 2000 driver. The core bean code can be deployed anywhere, but the sample deployment files are preconfigured for the aforementioned parameters.

For your workspace, you will need to either attain a copy of Jboss, or learn the deployment environment of your choice and set up a database connection pool that you can access from your bean. The following instructions describe how to add a database connection pool to JBoss 2.2.1 (I changed versions from 2.0 to 2.2.1 for this article because the configuration is different between the two, and I want to clarify the configuration here for those who read my previous articles.)

Configuring a DataSource in JBoss 2.2.1

The configuration of JBoss 2.2.1 is actually much easier than 2.0; it only requires the modification of one file—jboss.jcml—instead of three. Here are the steps:

  1. Copy your JDBC driver to JBoss's /lib/ext directory (for example, Sprinta2000.jar).

  2. Add your driver's class name to jboss.jcml's org.jboss.jdbc.JdbcProvider MBean tag (com.inet.tds.TdsDriver for the Sprinta 2000 driver):

  3. <mbean code="org.jboss.jdbc.JdbcProvider" 
        name="DefaultDomain:service=JdbcProvider">
     <attribute name="Drivers">
      org.hsql.jdbcDriver,org.enhydra.instantdb.jdbc.idbDriver,com.inet.tds.TdsDriver
     </attribute>
    </mbean>
  4. Set up a connection pool to a specific datasource in jboss.jcml:

  5. <mbean code="org.jboss.jdbc.XADataSourceLoader" 
        name="DefaultDomain:service=XADataSource,name=SQLServerPool">
      <attribute name="DataSourceClass">
       org.opentools.minerva.jdbc.xa.wrapper.XADataSourceImpl
      </attribute>
      <attribute name="PoolName">SQLServerPool</attribute>
      <attribute name="Properties">host=ServerName; database=DatabaseName</attribute>
      <attribute name="URL">jdbc:inetdae:localHost?database=informit</attribute>
      <attribute name="JDBCUser">sa</attribute>
      <attribute name="Password"></attribute>
      <attribute name="MinSize">0</attribute>
      <attribute name="MaxSize">10</attribute>
      <attribute name="GCEnabled">false</attribute>
      <attribute name="GCMinIdleTime">1200000</attribute>
      <attribute name="GCInterval">120000</attribute>
      <attribute name="InvalidateOnError">false</attribute>
      <attribute name="TimestampUsed">false</attribute>
      <attribute name="Blocking">true</attribute>
      <attribute name="LoggingEnabled">false</attribute>
      <attribute name="IdleTimeoutEnabled">false</attribute>
      <attribute name="IdleTimeout">1800000</attribute>
      <attribute name="MaxIdleTimeoutPercent">1.0</attribute>
    </mbean>

In this example, we set up a database connection pool with the following parameters:

  • Name: "SQLServerPool"

  • URL: "jdbc:inetdae:localHost?database=informit" (which points to a database in SQL Server named "informit")

  • Username: "sa"

  • Password: none

  • JDBC Driver class: "com.inet.tds.TdsDriver"

Just substitute your own database parameters into the locations I have described to create a mapping to any database. Furthermore, JBoss provides a rich set of documentation thatdescribes the configuration of databases within its product on its Web site (http://www.jboss.org).

The example we will work through is the development of an entity bean that represents a contact that you might find in a Personal Information Manager (PIM) application, as shown in Table 1.

Table 1 Contact Table

Field

Description

Datatype

id

Primary Key

NUMBER

name

Contact's name

VARCHAR

address

Contact's address

VARCHAR

city

Contact's city

VARCHAR

state

Contact's state

VARCHAR

zip

Contact's Zip code

VARCHAR

phone

Contact's phone number

VARCHAR

email

Contact's email address

VARCHAR

  • + Share This
  • 🔖 Save To Your Account