Server and middleware: jboss4.0 data source configuration

Source: Internet
Author: User
Tags ibm db2 informix

JBoss 4.0 is an open-source application server that uses hypersonicdb as its default database. However, developers may also need to use other types of databases except hypersonicdb. In this article, we will see how to configure other databases on JBoss.

Introduction

Jboss4.0 uses the JDBC configuration file to configure database connections. It provides data sources for access between ejbs and other J2EE applications. If you want to use a database other than hypersonicdb, You need to modify this configuration file. This article focuses on the following parts:

JBoss EJB deployment descriptor
Oralce Database Configuration
MySQL Database Configuration
Sysbase Database Configuration
DB2 database configuration
Infomix Database Configuration
JBoss EJB deployment descriptor

 
Standardjaws. XML (located in X:/jboss4/Server/default/conf) is a CMP ing CMP
The standard deployment description file of the object EJB. It is used to configure the CMP Entity EJB. You can also use jaws. xml instead. You can copy this file to EJB
Under the META-INF directory in the. jar file. This file is used to describe the following information:

Describes a data source and ing type.
Description of the EJB ing table
Description of the EJB finder Method
Description type ing

The data source here describes a JNDI name, which can be used to obtain a data source connection pool. Jboss4 uses hypersonicdb by default. If other data sources are used, you need to modify the jaws. xml file.

 
The standardjbosscmp-jdbc.xml (located at X:/jboss4/Server/default/conf) is to configure JBoss
The CMP container's standard deployment description file, you can also use a custom configuration file-jbosscmp-jdbc.xml to replace it. This file is also stored in the EJB. JAR File
In the META-INF directory. Hypersonicdb is used as the database by default, which also needs to be modified here.

Oracle Database Configuration

 
Oracle has become a very popular enterprise-level database for its stability and reliability. To be in JBoss
The first thing we need to do when configuring oracle is to copy the JDBC driver of Oracle to classpath. Copy the JDBC driver
Server/default/lib directory. To use Oracle's transaction processing data source, we also need to/docs/examples/JCA/Oracle-
The xa-ds.xml is copied to the/Server/default/deploy directory. If the data source used is not a data source for transaction processing, set/docs/Examples
/JCA/oracle-ds.xml file to the/Server/default/deploy directory.
Next, we need to modify the oracle-de.xml configuration file. The <driver-class/> label and <connection-URL/> label are set 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: @ Oracle oci xa type 2 driver
Class: Oracle. JDBC. Xa. Client. oraclexadatasource
URL: JDBC: oracle: thin: @ Oracle OCI type 2 driver
Class: Oracle. JDBC. Driver. oracledriver
URL: JDBC: oracle: oci8: @ <database>

 
In Connection
In the URL, Modify the standardjaws. xml or Jaws. xml configuration file, and set <datasource> and
The <type-mapping> element is as follows:
<Jaws>
<Datasource> JAVA:/oracleds </datasource>
<Type-mapping> oracle8 </type-mapping>
</Jaws>
Next, modify the standardjbosscmp-jdbc.xml or jbosscmp-jdbc.xml profile and set 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 the login-config.xml file to use Oracle. below is the <application-Policy> element of the login-config.xml file:
<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>
Modified oracle-ds.xml, standardjaws. XML, standardjbosscmp-jdbc.xml, and
After the login-config.xml file, you can use Oracle in jboss4.
MySQL Database Configuration

 
MySQL is an open-source database that is used by many open-source projects and small organizations. To use MySQL in jboss4, you must first use the JDBC driver of MySQL.
Put it in classpath. Similarly, copy it to the/Server/default/lib directory, and then copy/docs/examples/JCA/MySQL-
Copy Ds. XML to the/Server/default/deploy directory. Modify the mysql-ds.xml file and set <driver-class/>
Com. MySQL. JDBC. Driver and then set <connection-URL/>
JDBC: mysql: // <mysqlhost>/<database>, where <mysqlhost> is the Database Host Name <database> is the database name.

Then you need to set the <datasource> and <type-mapping> elements of the standardjaws. xml or Jaws. xml file:
<Jaws>
<Datasource> JAVA:/mysqlds </datasource>
<Type-mapping> mysql </type-mapping>
</Jaws>
You also need to set the <datasource> and <datasource-mapping> elements of the standardjbosscmp-jdbc.xml or jbosscmp-jdbc.xml file to the following:
<Jbosscmp-jdbc>
<Defaults>
<Datasource> JAVA:/mysqlds </datasource>
<Datasource-mapping> mysql </datasource-mapping>
</Defaults>
</Jbosscmp-jdbc>
Finally modify the login-config.xml file to use MySQL:
<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>
Modified the mysql-ds.xml, standardjaws. XML, standardjbosscmp-jdbc.xml, and login-config.xml files to use MySQL on JBoss.

Sysbase Database Configuration

 
Sybase Adaptive Server
Enterprises (ASE) is a database server of sysbase. ASE can be used on UNIX and Linux platforms. Similarly, we need to put its database driver in
In classpath, copy it to the/Server/default/lib directory, and then/docs/examples/JCA/SYBASE-
DS. xml
Copy to the/Server/default/deploy directory. Modify the sybase-ds.xml file to set <driver-class/>
Com. Sybase. jdbc2.jdbc. sybdriver and set <connection-URL/>
JDBC: Sybase: TDS: Port name and database name. You also need to modify the <datasource> of the standardjaws. xml or Jaws. xml file
And <type-mapping> elements:
<Jaws>
<Datasource> JAVA:/sybaseds </datasource>
<Type-mapping> Sybase </type-mapping>
</Jaws>
Modify the <datasource> and <datasource-mapping> elements of the standardjbosscmp-jdbc.xml or jbosscmp-jdbc.xml file again:
<Jbosscmp-jdbc>
<Defaults>
<Datasource> JAVA:/sybaseds </datasource>
<Datasource-mapping> Sybase </datasource-mapping>
</Defaults>
</Jbosscmp-jdbc>
Finally, modify the login-config.xml file to use the sysbase database. Set the <application-policy/> element:
<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>
Modified sybase-ds.xml, standardjaws. XML, standardjbosscmp-jdbc.xml, and
You can use sysbase in JBoss after the login-config.xml file.


DB2 database configuration

 
IBM DB2 is a complete and easy-to-use database server that can be used on Linux, UNIX, and Windows platforms. To use DB2 on jboss4
Copy db2java.zip to the/Server/default/lib directory. Then copy/docs/examples/JCA/db2-ds.xml
/Server/default/deploy directory, and then modify the <driver-class/> element bit
Com. IBM. db2.jdbc. App. db2driver, the <connection-URL/> element is
JDBC: DB2: The <database> element represents the Database Service name.
<Jaws>
<Datasource> JAVA:/db2ds </datasource>
<Type-mapping> DB2 </type-mapping>
</Jaws>
Below is the corresponding standardjbosscmp-jdbc.xml (or jbosscmp-jdbc.xml) file:
<Jbosscmp-jdbc>
<Defaults>
<Datasource> JAVA:/db2ds </datasource>
<Datasource-mapping> DB2 </datasource-mapping>
</Defaults>
</Jbosscmp-jdbc>
Finally, add the following content to the login-config.xml file:
<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>
After completing the preceding configuration, you can use DB2 on JBoss.

Informix Database Configuration

 
The IBM infoxmix database server is used as a data warehouse, analysis, and report. To use the Informix database on jboss4, you must first drive the corresponding database JDBC
Dynamic copy to the/Server/default/lib directory, and then copy/docs/examples/JCA/informix-ds.xml
In the/Server/default/deploy directory, if you are using transaction (xa) JDBC, copy the/docs/examples/JCA
/Informix-xa-ds.xml file.

The next step is to modify the informix-ds.xml file and set the <driver-class/> element:
Com. Informix. JDBC. ifxdriver set the <connection-URL/> element
JDBC: Informix-sqli: // <Host>, <port>, and <ifx_server> indicate the Database Host Name, database port, and database service name respectively. Modify the <datasource> and <type-mapping> elements of the standardjaws. xml or Jaws. xml file:
<Post>
<Jaws>
<Datasource> JAVA:/informixds </datasource>
<Type-mapping> informixdb </type-mapping>
</Jaws>
Set the <datasource> and <datasource-mapping> elements in the standardjbosscmp-jdbc.xml or jbosscmp-jdbc.xml file to the following:
<Jbosscmp-jdbc>
<Defaults>
<Datasource> JAVA:/informixds </datasource>
<Datasource-mapping> informixdb </datasource-mapping>
</Defaults>
</Jbosscmp-jdbc>
Finally add the <application-policy/> element to the login-config.xml file:
<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>
In this way, you can use the Informix Database in jboss4.

Conclusion

Jboss4 uses the hypersonic database by default, but as you can see, we only need to modify several configuration files to use other popular databases on the market.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.