Jboss4.0 JDBC 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:

L JBoss EJB deployment descriptor

L oralce Database Configuration

L MySQL Database Configuration

L sysbase Database Configuration

L DB2 database configuration

L infomix Database Configuration

JBoss EJB deployment descriptor

Standardjaws. XML (in X: jboss4serverdefaconf conf) is a standard deployment description file mapped to the CMP Entity EJB. It is used to configure the CMP Entity EJB. You can also use jaws. xml instead. You can copy this file to the META-INF directory in the EJB. jar file. This file is used to describe the following information:

Sysbase Database Configuration

Sybase Adaptive Server pair ISES (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 classpath and copy it to the/Server/default/lib directory, then copy/docs/examples/JCA/sybase-ds.xml to the/Server/default/deploy directory. Modify the sybase-ds.xml file to set <driver-class/> to com. sybase. jdbc2.jdbc. sybdriver then sets <connection-URL/> As JDBC: Sybase: TDS:

<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 db2on jboss4, you only need to copy db2java.zip to the/Server/default/lib directory. Then copy/docs/examples/JCA/db2-ds.xml to the/Server/default/deploy directory and modify the <driver-class/> element bit COM. IBM. db2.jdbc. app. db2driver. The <connection-URL/> element is JDBC: DB2. The <database> element indicates 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, first copy the JDBC driver of the corresponding database to the/Server/default/lib directory. Then, copy/docs/examples/JCA/informix-ds.xml to the/Server/default/deploy directory if you are using transaction (xa) JDBC copies the/docs/examples/JCA/informix-xa-ds.xml file.

The next step is to modify the informix-ds.xml file, set the <driver-class/> element to: COM. Informix. JDBC. ifxdriver to 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.

L describes a data source and ing type.

L description of the EJB ing table

L description of the EJB finder Method

L 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.

Standardjbosscmp-jdbc.xml (located in X: jboss4serverdefaconf conf) is the standard deployment description file for configuring the JBoss CMP container, and you can also replace it with a custom configuration file-jbosscmp-jdbc.xml. This file is also placed in the META-INF directory of the EJB. jar file. 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 configure oracle on JBoss, copy the JDBC driver of Oracle to classpath. Copy the JDBC driver to the server/default/lib directory. To use Oracle's transaction processing data source, we also need to copy/docs/examples/JCA/oracle-xa-ds.xml to the/Server/default/deploy directory. If you are using a non-transactional data source, copy the/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 the connection URL,

<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 put the JDBC driver of MySQL into classpath. Similarly, copy it to the/Server/default/lib directory, and then copy/docs/examples/JCA/mysql-ds.xml to the/Server/default/deploy directory. Modify the mysql-ds.xml file, set <driver-class/> to 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.

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.