This document explains the steps required to use the DataDirect Connect® for JDBC® drivers with the JBoss Application Server1. These steps include:
Detailed information about each of these steps is included in the following sections.
First, install the DataDirect Connect for JDBC drivers using the instructions in the DataDirect Connect for JDBC Installation Guide.
Next, copy the DataDirect Connect for JDBC jar files (util.jar, base.jar, db2.jar, informix.jar, oracle.jar, sqlserver.jar, and sybase.jar) from:
install_dir/lib
to:
JBoss_home/server/server_config/lib
where install_dir is your DataDirect Connect for JDBC installation directory, JBoss_home is your JBoss installation directory, and server_config is your server configuration directory.
For example, to configure the DataDirect Connect for JDBC drivers for the default JBoss server configuration, copy the driver jar files to JBoss_home/server/default/lib.
java:ds/TestDS
<driver-class>
com.ddtek.jdbc.sqlserver.SQLServerDriver
</driver-class>
<
user
-
name
>test</
user
-
name
>
<
password
>secret</
password
>
"
<connection-property name="
sendStringParametersAsUnicode">
false
</
connection
-property>
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<!-- =========================================================== -->
<!-- -->
<!-- DataDirect Data Sources -->
<!-- -->
<!-- =========================================================== -->
<!--
See the generic_ds.xml file in the doc/examples/jca folder
for examples of properties and other tags you can specify
in data sources
-->
<
datasources
>
<!-- JBossTest Data Source -->
<
local-tx-datasource
>
<
jndi-name
>ds/TestDS</
jndi-name
>
<
connection-url
>
jdbc:datadirect:sqlserver://myserver:1433
</
connection-url
>
<
driver-class
>
com.ddtek.jdbc.sqlserver.SQLServerDriver
</
driver-class
>
<
user-name
>test</
user-name
>
<
password
>secret</
password
>
<!-- Driver Specific Options -->
<
connection-property
name
=
"sendStringParametersAsUnicode"
>
false
</
connection-property
>
<!--pooling parameters-->
<
min-pool-size
>5</
min-pool-size
>
<
max-pool-size
>100</
max-pool-size
>
<
blocking-timeout-millis
>5000</
blocking-timeout-millis
>
<
idle-timeout-minutes
>15</
idle-timeout-minutes
>
</
local-tx-datasource
>
</
datasources
>
You must create a JSP page that uses the data source you created in the previous step. A sample JSP page named JBossTest.jsp is provided in the JBossTestWeb.war file, which is available from the same location you obtained this document. This JSP page includes the following code to look up the data source and obtain a connection to the database from the data source.
InitialContext ctxt = new InitialContext();
DataSource ds = (DataSource) ctxt.lookup(
"java:ds/TestDS"
);
con = ds.getConnection();
Copy the JBossTestWeb.war file, available with this document, to the directory JBoss_home/server/server_config/deploy.
run -c
all
http://localhost:8080/JBossTestWeb/JBossTest.jsp
The contents of the page display the version information of the driver and the database server to which it connects, if the DataDirect Connect for JDBC driver has been installed and configured correctly. For example, the following figure shows version information for the DataDirect Connect for JDBC SQL Server driver connecting to a database server running Microsoft SQL Server 2000.
Typically an EJB does not use the global JNDI name to look up the data source. Instead, it uses a logical JNDI name that is mapped to the global JNDI name of the data source.
To map a logical JNDI name to the global JNDI data source name in a Session EJB, declare a resource reference in the JBoss-specific deployment descriptor file jboss.xml. A resource reference is defined by adding the tag <resource-ref> as a child of the <session> tag as shown in the following example.
<
session
>
<
ejb-name
>SupportedDatabases</
ejb-name
>
<
jndi-name
>SupportedDatabasesBean</
jndi-name
>
<
local-jndi-name
>SupportedDatabasesLocal</
local-jndi-name
>
<
resource-ref
>
<
res-ref-name
>jdbc/TestDS</
res-ref-name
>
<
jndi-name
>java:/ds/TestDS</
jndi-name
>
</
resource-ref
>
</
session
>
The value of the <res-ref-name> tag is the logical JNDI name an EJB uses to look up the data source. The value of the <jndi-name> tag is the global name of the data source to which the logical name is mapped.
Refer to your JBoss documentation for more information about JBoss-specific deployment descriptors.
To specify the data source to be used with an Entity EJB, specify the global JNDI name of the data source in the JBoss-specific Container Manager Persistence (CMP) deployment descriptor, jbosscmp-jdbc.xml. The value of the <datasource> tag specifies the global JNDI name of the data source to use with Entity EJBs. The <datasource> tag can be specified as a child of the <defaults> tag as shown in the following example, or it can be specified as a child of a particular <entity> tag.
<
defaults
>
<
datasource
>java:/ds/TestDS</
datasource
>
<
datasource-mapping
>MS SQLSERVER</
datasource-mapping
>
</
defaults
>
Refer to your JBoss documentation for more information about JBoss-specific deployment descriptors.
1 The steps in this paper were generated using JBoss 3.2.3. These steps may vary for other versions of JBoss.