Home Database Mysql Tutorial JBOSS4 数据源配置大全(一)_MySQL

JBOSS4 数据源配置大全(一)_MySQL

Jun 01, 2016 pm 01:54 PM
develop database data source article

Jboss 4.0的开发人员版本是一个开源的应用服务器,他把HypersonicDB作为他的缺省数据库。然而,开发人员也许还要使用除了HypersonicDB以外其他种类的数据库,在这篇文章中我们将看到如何在Jboss上配置使用其他的数据库。

简介

Jboss4.0使用了JDBC配置文件来配置数据库连接,它为EJB和其它J2EE应用提供了数据源(data source)进行访问。如果你要使用HypersonicDB以外的数据库你就要修改这个配置文件。这篇文章将着重讲解下面的几个部分:


Jboss的EJB部署描述符

Oralce数据库的配置

MySQL数据库的配置

Sysbase数据库的配置

DB2数据库的配置

Infomix数据库的配置

Jboss的EJB部署描述符

standardjaws.xml (位于X:/jboss4/server/default/conf)是一个映射CMP 实体EJB的标准部署描述文件。它用于配置CMP实体EJB,你也可以使用jaws.xml代替。你可以把这个文件copy到ejb .jar文件中的META-INF目录下。这个文件用于描述下面的信息:


描述一个数据源和映射类型

描述EJB映射的表

描述EJB的finder方法

描述类型映射

这里的数据源描述的是一个JNDI名称,可以通过这个JNDI来获得一个数据源连接池。Jboss4缺省的数据源使用的是HypersonicDB。如果使用其他的数据源你需要修改jaws.xml文件。

standardjbosscmp-jdbc.xml(位于X:/jboss4/server/default/conf)是配置Jboss CMP容器的标准部署描述文件,你也可以使用一个自定义的配置文件--jbosscmp-jdbc.xml来代替它。这个文件也放在EJB.jar文件的META-INF目录中。缺省使用的还是HypersonicDB作为数据库,这里也需要修改。

Oracle数据库的配置

Oracle以它的运行稳定和可靠成为了一个非常受欢迎的企业级数据库。要在Jboss 上配置使用Oracle的话我们要做的第一件事就是把Oracle的JDBC驱动程序复制到ClassPath下。我们把这个JDBC驱动程序复制到server/default/lib目录下。为了使用Oracle的事务处理数据源我们还要把/docs/examples/jca/oracle-xa-ds.xml复制到/server/default/deploy目录下。如果使用的事非事务处理的数据源,就把/docs/examples/jca/oracle-ds.xml文件复制到/server/default/deploy目录下。

下一步,我们需要修改oracle-de.xml配置文件。其中的标签和标签的设置如下:

Oracle OCI Type 2 Driver
Class: oracle.jdbc.driver.OracleDriver
URL: jdbc:oracle:oci8:@
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:@


在Connection URL中是安装Oracle的计算机主机名,是oracle数据库的端口,是数据库名称。下一步,我们将修改standardjaws.xml 或jaws.xml配置文件,并把 和 元素这只为下面这样:


   java:/OracleDS
   Oracle8


下一步,再修改standardjbosscmp-jdbc.xml 或 jbosscmp-jdbc.xml配置文件,设置 和 元素使用Oracle。


  
      java:/OracleDS
      Oracle8
  


最后我们需要修改login-config.xml文件来使用Oracle,下面是login-config.xml文件的元素:


  
        "org.jboss.resource.security.ConfiguredIdentityLoginModule"
                            flag = "required">
         sa
         sa
        
          
                   jboss.jca:service=LocalTxCM,name=OracleDS
        

     

  


修改了oracle-ds.xml, standardjaws.xml, standardjbosscmp-jdbc.xml,和

login-config.xml 文件之后就可以再Jboss4中使用Oracle了。

MySQL数据库配置

MySQL是一个开放源代码的数据库,有很多开源项目和小型的社团都在使用它。要在Jboss4中使用MySQL的话首先要把MySQL的JDBC驱动放到CLASSPATH中。同样,把它复制到/server/default/lib目录下,再把/docs/examples/jca/mysql-ds.xml复制到/server/default/deploy目录下。修改mysql-ds.xml文件,设置为 com.mysql.jdbc.Driver再把设置为

jdbc:mysql:///,其中是数据库主机名是数据库名。

然后需要设置standardjaws.xml 或 jaws.xml文件的和元素:


  java:/MySqlDS
  mySql


同样也需要把standardjbosscmp-jdbc.xml 或 jbosscmp-jdbc.xml文件的 和 元素设置为下面这样:


   
       java:/MySqlDS
       mySql
 


最后再修改login-config.xml文件来使用MySQL:


  
        "org.jboss.resource.security.ConfiguredIdentityLoginModule"
                            flag = "required">
         sa
         sa
        
          
            jboss.jca:service=LocalTxCM,name=MySqlDS
        

     

  


修改了mysql-ds.xml, standardjaws.xml, standardjbosscmp-jdbc.xml,和

login-config.xml 文件就可以在Jboss上使用MySQL了。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1269
29
C# Tutorial
1248
24
iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How do new features of PHP functions simplify the development process? How do new features of PHP functions simplify the development process? May 04, 2024 pm 09:45 PM

The new features of PHP functions greatly simplify the development process, including: Arrow function: Provides concise anonymous function syntax to reduce code redundancy. Property type declaration: Specify types for class properties, enhance code readability and reliability, and automatically perform type checking at runtime. null operator: concisely checks and handles null values, can be used to handle optional parameters.

How to use database callback functions in Golang? How to use database callback functions in Golang? Jun 03, 2024 pm 02:20 PM

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

How to save JSON data to database in Golang? How to save JSON data to database in Golang? Jun 06, 2024 am 11:24 AM

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

How to connect to remote database using Golang? How to connect to remote database using Golang? Jun 01, 2024 pm 08:31 PM

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.

How to handle database connections and operations using C++? How to handle database connections and operations using C++? Jun 01, 2024 pm 07:24 PM

Use the DataAccessObjects (DAO) library in C++ to connect and operate the database, including establishing database connections, executing SQL queries, inserting new records and updating existing records. The specific steps are: 1. Include necessary library statements; 2. Open the database file; 3. Create a Recordset object to execute SQL queries or manipulate data; 4. Traverse the results or update records according to specific needs.

See all articles