Jboss4 data source configuration (1)

Source: Internet
Author: User
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 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:

  • Description of 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 the standard deployment description file for configuring the JBoss CMP container, you can also replace it with a custom profile -- 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 Labels and The tag settings are as follows:


          Oracle OCI Type 2 DriverClass: oracle.jdbc.driver.OracleDriver URL: jdbc:oracle:oci8:@<database> Oracle OCI Thin Type 4 DriverClass: oracle.jdbc.driver.OracleDriver URL: jdbc:oracle:thin:@

    In the connection URL Is the Host Name of the Oracle computer, Is the port of the Oracle database, Is the database name. Next, we will modify the standardjaws. xml or Jaws. xml configuration file and And The 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 configuration file and set And The element uses 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 login-config.xml FileElement:


          <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 and set For com. MySQL. JDBC. Driver Set

    JDBC: mysql :// / , Where Is the Database Host Name Is the database name.

    Then you need to set the standardjaws. xml or Jaws. xml file And Element:


          <jaws>  <datasource>java:/MySqlDS</datasource>   <type-mapping>mySql</type-mapping></jaws>

    Also need to put the standardjbosscmp-jdbc.xml or jbosscmp-jdbc.xml File And The element is set as follows:


          <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 mysql-ds.xml, standardjaws. XML, standardjbosscmp-jdbc.xml, and

    The login-config.xml file can use MySQL on JBoss.

    Author's blog:Http://blog.csdn.net/zaowei21/
  • Author's blog:Http://blog.csdn.net/zaowei21/

    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.