Configuring JBoss 4.0 JDBC Connectivity
JBoss 4.0, developer edition, is an open source application server configured to use HypersonicDB by default. However, some Java 2 Platform Enterprise Edition (J2EE) developers would like to use databases other than HypersonicDB to develop and deploy applications. In this tutorial, we'll look at how to configure JBoss to use other databases.
<!-- Digital Media MPU Ad --><!-- Network MPU Ad -->
<script src="http://ocp.com.com/ad.js" type="text/javascript"></script><script type="text/JavaScript">
<!--
var CN_AD = new Object();
CN_AD.AD_SZ = "300wX250h";
CN_AD.PTYPE = "publisher";
cnetGetAd(CN_AD);
//-->
</script><script src="http://mads.com.com/cnet-ad?CLIENT:ID=SJS&celt=js&x-cb=31859269&AD_SZ=300wX250h&PTYPE=publisher" type="text/javascript"></script><!-- no overgif in ad style -->
<!-- End ad --><!-- me -->
Overview
The JBoss 4.0 server makes use of Java Database Connectivity (JDBC) configuration files to configure the server. The JBoss application server provides data source access for Enterprise Java Beans (EJB) persistence, and other for J2EE applications. To use the server with a database other than the default database, Hypersonic, these configuration files have to be modified. This article is structured into the following sections:
-
JBoss Deployment Descriptors for EJBs
-
Oracle Database Configuration
-
MySQL Database Configuration
-
Sybase Database Configuration
-
DB2 Database Configuration
-
Informix Database Configuration
JBoss Deployment Descriptors for EJBs
standardjaws.xml is the standard deployment descriptor for the mapping of Container Managed Persistence (CMP) entity EJBs. To use a custom configuration for mapping CMP entity EJBs, you use the jaws.xml file instead. In both cases, the file is copied to the META-INF directory of the EJB .jar file. Whichever file is used configures the following:
<!-- sidebar begins --><!-- don't move sidebars --><!-- sidebar ends --><!-- sidebar begins -->
<!-- sidebar ends -->
- Specify a data source and a type mapping for the data source.
- Specify how tables are built/used.
- Define finder methods to access the entity beans.
- Define type mappings.
A data source is a Java Naming and Directory Interface (JNDI) object used to obtain a connection from a connection pool to a database. The default data source configured with JBoss 4.0 is the HypersonicDB data source. To use another database, you need to modify jaws.xml or standardjaws.xml.
standardjbosscmp-jdbc.xml is the standard deployment descriptor to configure the JBoss CMP container. It can be replaced with a custom configuration version, called jbosscmp-jdbc.xml. As before, this file goes in the META-INF directory of the EJB .jar file. And once again, JBoss 4.0 defaults to a Hypersonic version, in this case HypersonicDB cmp. To use another database, we need to edit this file.
Oracle Configuration
Oracle is a very popular enterprise database used for its performance and reliability. To configure JBoss 4.0 with Oracle, we first need to put Oracle's driver classes in the CLASSPATH
. Copy Oracle's JDBC driver .zip file /jdbc/lib/classes12.zip to the server/default/lib directory.
To use Oracle's transactional (XA) data source, copy /docs/examples/jca/oracle-xa-ds.xml to the /server/default/deploy directory. To configure with the non-XA data source, copy /docs/examples/jca/oracle-ds.xml instead, to /server/default/deploy dir.
Next, we need to modify the oracle-ds.xml configuration file. The <driver-class/>
and <connection-url/>
settings for Oracle are as follows:
Oracle OCI Type 2 Driver
-
Class:
oracle.jdbc.driver.OracleDriver
-
URL:
jdbc:oracle:oci8:@<database>
Oracle OCI Thin Type 4 Driver
-
Class:
oracle.jdbc.driver.OracleDriver
-
URL:
jdbc:oracle:thin:@<host>:<port>:<database>
Oracle OCI XA Type 2 Driver
-
Class:
oracle.jdbc.xa.client.OracleXADataSource
-
URL:
jdbc:oracle:thin:@<host>:<port>:<database>
Oracle OCI Type 2 Driver
-
Class:
oracle.jdbc.driver.OracleDriver
-
URL:
jdbc:oracle:oci8:@<database>
In the Connection URL setting, <host>
is the HOST
value specified in the /network/ADMIN/tnsnames.ora file, and <port>
is the PORT
value specified in the tnsnames.ora file, and <database>
is the database name.
Next, we modify the standardjaws.xml or jaws.xml configuration file. Set the <datasource>
and <type-mapping>
elements as follows:
<jaws>
<datasource>java:/OracleDS</datasource>
<type-mapping>Oracle8</type-mapping>
</jaws>
Next, we modify the standardjbosscmp-jdbc.xml or jbosscmp-jdbc.xml configuration file, setting the <datasource>
and <datasource-mapping>
elements to use Oracle:
<jbosscmp-jdbc>
<defaults>
<datasource>java:/OracleDS</datasource>
<datasource-mapping>Oracle8</datasource-mapping>
</defaults>
</jbosscmp-jdbc>
Finally, we need to modify login-config.xml to use Oracle. Add the following <application-policy>
element to login-config.xml:
<application-policy name = "OracleDbRealm">
<authentication>
<login-module code =
"org.jboss.resource.security.ConfiguredIdentityLoginModule"
flag = "required">
<module-option name = "principal">sa</module-option>
<module-option name = "userName">sa</module-option>
<module-option name = "password"></module-option>
<module-option name ="managedConnectionFactoryName">
jboss.jca:service=LocalTxCM,name=OracleDS
</module-option>
</login-module>
</authentication>
</application-policy>
By modifying the oracle-ds.xml, standardjaws.xml, standardjbosscmp-jdbc.xml, and login-config.xml files, the JBoss 4.0 server is configured to be used with a Oracle database.
MySQL Database Configuration
MySQL is an open source database used by many open source projects and small organizations. To use JBoss 4.0 with MySQL, we first need to put the MySQL driver classes into the CLASSPATH
. Copy the .jar file mysql-connector-java-3.0.9-stable-bin.jar to the /server/default/lib directory.
To use the MySQL data source, copy /docs/examples/jca/mysql-ds.xml to the /server/default/deploy directory. Modify the mysql-ds.xml configuration file by setting <driver-class/>
to com.mysql.jdbc.Driver
and <connection-url/>
to jdbc:mysql://<mysqlhost>/<database>
, where <mysqlhost>
is the MySQL host server and <database>
is the MySQL database.
Next, we need to set the <datasource>
and <type-mapping>
elements in the standardjaws.xml or jaws.xml file:
<jaws>
<datasource>java:/MySqlDS</datasource>
<type-mapping>mySQL</type-mapping>
</jaws>
We also need to set the <datasource>
and <datasource-mapping>
elements in the standardjbosscmp-jdbc.xml or jbosscmp-jdbc.xml file:
<jbosscmp-jdbc>
<defaults>
<datasource>java:/MySqlDS</datasource>
<datasource-mapping>mySQL</datasource-mapping>
</defaults>
</jbosscmp-jdbc>
Finally, we modify login-config.xml with MySQL database settings. Add the following <application-policy/>
element to login-config.xml:
<application-policy name = "MySqlDbRealm">
<authentication>
<login-module code =
"org.jboss.resource.security.ConfiguredIdentityLoginModule"
flag = "required">
<module-option name ="principal">sa</module-option>
<module-option name ="userName">sa</module-option>
<module-option name ="password"></module-option>
<module-option name ="managedConnectionFactoryName">
jboss.jca:service=LocalTxCM,name=MySqlDS
</module-option>
</login-module>
</authentication>
</application-policy>
By modifying the mysql-ds.xml, standardjaws.xml, standardjbosscmp-jdbc.xml, and login-config.xml files, the JBoss 4.0 server is configured to be used with a MySQL database.
Sybase Database Configuration
Sybase Adaptive Server Enterprise (ASE) is a database server by Sybase Inc. ASE is used on both UNIX and Linux platforms. As before, the first step is getting the database driver classes into the CLASSPATH
, by copying the .jar file jconn2.jar to the /server/default/lib directory. Then use its data source by copying /docs/examples/jca/sybase-ds.xml to /server/default/deploy dir.
Modify the sybase-ds.xml configuration file, setting <driver-class/>
to com.sybase.jdbc2.jdbc.SybDriver
and <connection-url/>
to jdbc:sybase:Tds:<host>:<port>/<database>
, where <host>
is the Sybase host server, <port>
is the Sybase host server port number, and <database>
is the Sybase database name.
Then, as before, we need to modify standardjaws.xml or jaws.xml to set the <datasource> and
<type-mapping>
elements:
<jaws>
<datasource>java:/SybaseDS</datasource>
<type-mapping>Sybase</type-mapping>
</jaws>
We also need to modify standardjbosscmp-jdbc.xml or jbosscmp-jdbc.xml to set the <datasource>
and <datasource-mapping>
elements:
<jbosscmp-jdbc>
<defaults>
<datasource>java:/SybaseDS</datasource>
<datasource-mapping>Sybase</datasource-mapping>
</defaults>
</jbosscmp-jdbc>
Finally, we modify login-config.xml to use the Sybase database. Add the following <application-policy/>
element to the file:
<application-policy name = "SybaseDbRealm">
<authentication>
<login-module code =
"org.jboss.resource.security.ConfiguredIdentityLoginModule"
flag = "required">
<module-option name ="principal">sa</module-option>
<module-option name = "userName">sa</module-option>
<module-option name = "password"></module-option>
<module-option name = "managedConnectionFactoryName">
jboss.jca:service=LocalTxCM,name=SybaseDS
</module-option>
</login-module>
</authentication>
</application-policy>
By modifying the sybase-ds.xml, standardjaws.xml, standardjbosscmp-jdbc.xml, and login-config.xml, the JBoss 4.0 server is configured to be used with a Sybase database.
DB2 Database Configuration
IBM's DB2 Universal Database is a full-featured, robust, scalable, and easy-to-use database server that may be used on Linux, UNIX, and Windows platforms.
We begin by adding its driver to the CLASSPATH
: copy db2java.zip to the /server/default/lib directory. To configure the JBoss server with the DB2 data source, copy /docs/examples/jca/db2-ds.xml to the /server/default/deploy directory.
Next we modify the db2-ds.xml configuration file, by setting <driver-class/>
to COM.ibm.db2.jdbc.app.DB2Driver
and <connection-url/>
to jdbc:db2:<database>
, where <database>
is the DB2 database name.
Then we modify standardjaws.xml (or jaws.xml) to set <datasource>
and <type-mapping>
.
<jaws>
<datasource>java:/DB2DS</datasource>
<type-mapping>DB2</type-mapping>
</jaws>
And standardjbosscmp-jdbc.xml (or jbosscmp-jdbc.xml):
<jbosscmp-jdbc>
<defaults>
<datasource>java:/DB2DS</datasource>
<datasource-mapping>DB2</datasource-mapping>
</defaults>
</jbosscmp-jdbc>
Finally, we add the following <application-policy/>
element to login-config.xml:
<application-policy name = "DB2DbRealm">
<authentication>
<login-module code =
"org.jboss.resource.security.ConfiguredIdentityLoginModule"
flag = "required">
<module-option name =
"principal">sa</module-option>
<module-option name =
"userName">sa</module-option>
<module-option name =
"password"></module-option>
<module-option name ="managedConnectionFactoryName">
jboss.jca:service=LocalTxCM,name=DB2DS
</module-option>
</login-module>
</authentication>
</application-policy>
These configuration changes allow us to use DB2 with JBoss.
Informix Database Configuration
IBM's Informix database servers are used for data warehousing, analysis, and reporting. To use the JBoss 4.0 server with an Informix database, we start by putting Informix's .jar into the CLASSPATH
: add ifxjdbc.jar to the /server/default/lib directory. Then configure the data source by copying /docs/examples/jca/informix-ds.xml to the /server/default/deploy directory. If you are using the XA JDBC Informix driver, copy /docs/examples/jca/informix-xa-ds.xml instead.
Next we modify the informix-ds.xml configuration file by setting the <driver-class/>
to com.informix.jdbc.IfxDriver
and <connection-url/>
to jdbc:informix-sqli://<host>:<port>:informixserver=<ifx_server>
, where <host>
is the host server, <port>
is the Informix server port number, and <ifx_server>
is the Informix database name.
We set the <datasource>
and <type-mapping>
elements in standardjaws.xml or jaws.xml like this:
<jaws>
<datasource>java:/InformixDS</datasource>
<type-mapping>InformixDB</type-mapping>
</jaws>
We set the <datasource>
and <datasource-mapping>
elements of standardjbosscmp-jdbc.xml or jbosscmp-jdbc.xml like this:
<jbosscmp-jdbc>
<defaults>
<datasource>java:/InformixDS</datasource>
<datasource-mapping>InformixDB</datasource-mapping>
</defaults>
</jbosscmp-jdbc>
Finally, we add an <application-policy/>
element to login-config.xml:
<application-policy name = "InformixDbRealm">
<authentication>
<login-module code =
"org.jboss.resource.security.ConfiguredIdentityLoginModule"
flag = "required">
<module-option name = "principal">sa</module-option>
<module-option name = "userName">sa</module-option>
<module-option name = "password"></module-option>
<module-option name ="managedConnectionFactoryName">
jboss.jca:service=LocalTxCM,name=InformixDS
</module-option>
</login-module>
</authentication>
</application-policy>
These configuration changes allow us to use JBoss with an Informix database.
Conclusion
The JBoss 4.0 server is configured with the Hypersonic database by default, but as we've seen, it is a simple matter of changing a few configuration files to use any one of a number of popular databases.
Resource
JBoss Documentation
Deepak Vohra is a NuBean consultant and a web developer.
分享到:
相关推荐
Peter Johnson started working in Java in 1998, and was lead designer on projects such as a JDBC driver for the DMSII database that runs on Unisys mainframes. For the past several years he has been ...
JBoss in Action: Configuring the JBoss Application Server Publisher: Manning Publications | 2009-01-28 | ISBN: 1933988029 | PDF | 6,58 MB JBoss in Action is the first book to focus on teaching ...
It guides you through configuring the server抯 component containers, such as the JBoss Web Server, the EJB3 server, and JBoss Messaging. It also gives you detailed insight into configuring the ...
Implementing Cisco SD-WAN Solutions (SDWAN300) v1.0: 0 Welcome\ Section 1 - Cisco SD-WAN Overlay Network\ Section 2 - Cisco SD-WAN Deployment\ Section 3 Cisco SD-WAN Routing Options\ ...
It guides you through configuring the server’s component containers, such as the JBoss Web Server, the EJB3 server, and JBoss Messaging. It also gives you detailed insight into configuring the ...
AB PLC例程_本资料仅供学习参考
Configuring the JBoss Utility ServerJBoss in Motion is the primary e-book to deal with educating readers intimately how you can use the JBoss utility server. In contrast to different...
Configuring OSPF Authentication OSPF实验配置指南,认证配置方法,拓扑图,实验过程,实验现象。
MyEclipse_Remote_Debugging_Quickstart.pdf Outline 1. Preface 2. Introduction ...4. JBoss 4.0.x 4. Deploying to a Remote Server 5. Debugging a Remote Server 6. Summary 7. User Feedback
The book is about configuring the JBoss AS and the applications deployed to it. We start the book with a quick introduction into the JBoss Application Server (JBoss AS). Chapter 1 gets you up and ...
CISCO官方配置手册Cisco - Configuring RSTP and MSTP
Configuring Siebel Business Applications
win10安装Oracle创建数据库实例的时候到85%报出,由于以下错误,Enterprise Manager配置失败,点击确认后显示数据库实例安装成功,但是监听程序TNS一直不能连接本地数据库,用了网上的好多方法都没有解决(win10安装...
Prepare for Microsoft Exam 70-687 – and help demonstrate your real-world mastery of configuring Windows 8.1 in the enterprise. Designed for experienced IT professionals ready to advance their status...
Configuring Hardware with STEP 7pdf,Configuring Hardware with STEP 7
Configuring Altera FPGAs ,Device Configuration Overview for Passive Schemes.
PyCharm配置Windows10 WSL的Python环境 PyCharm Configuring Remote Interpreter via WSL
Configuring Controller 8.2 to use Active Directory authentication