程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> JBoss AS7配置MySQL數據源

JBoss AS7配置MySQL數據源

編輯:MySQL綜合教程

 

AS7默?認?的?數?據?源?是?H2,雖?然?H2方?便?,但?是?一?般?的?生?產?環?境?都?是?MySQL、?ORACLE、?SQLServer居?多?,本?文?描?述?如?何?在?AS7配?置?MySQL數?據?源?。?

根?據?Jboss社?區?的?文?檔?,配?置?一?個?新?的?數?據?源?大?致?分?為?兩?步?。?描?述?如?下?:

加?入?JDBC驅?動?文?件?

 

在?JBOSS_HOME/modules目?錄?下?加?入?如?下?目?錄?結?構?及?文?件?:

JBOSS_HOME

 +- modules

     +- com

         +- mysql

             +- main    

                 +- module.xml     

                 +- mysql-connector-java-5.1.15.jar   (mysql的jdbc驅動jar文件,版本根據各自情況而定)

                 +- mysql-connector-java-5.1.15.jar.index

module.xml的?內?容?如?下?:

例1. module.xml

<?xml version="1.0" encoding="UTF-8"?>

<module xmlns="urn:jboss:module:1.0" name="com.mysql">

  <resources>

    <resource-root path="mysql-connector-java-5.1.15.jar"/>

  </resources>

  <dependencies>

    <module name="javax.api"/>

  </dependencies>

</module>

 

 

mysql-connector-java-5.1.15.jar.index的?內?容?如?下?:

例2. mysql-connector-java-5.1.15.jar.index

META-INF

META-INF/services

com

com/mysql

com/mysql/jdbc

com/mysql/jdbc/configs

com/mysql/jdbc/exceptions

com/mysql/jdbc/exceptions/jdbc4

com/mysql/jdbc/interceptors

com/mysql/jdbc/jdbc2

com/mysql/jdbc/jdbc2/optional

com/mysql/jdbc/jmx

com/mysql/jdbc/log

com/mysql/jdbc/profiler

com/mysql/jdbc/util

org

org/gjt

org/gjt/mm

org/gjt/mm/mysql

 

 

添?加?Server數?據?源?配?置?

 

AS7啟?動?分?為?兩?種?形?式?,一?種?是?domain形?式?的?,一?種?是?standalone,這?裡?我?們?選?擇?standalone。?

打?開?JBOSS_HOME\standalone\configuration\standalone.xml文?件?,在?<datasources>下?添?加?如?下?內?容?:

例3. mysql-connector-java-5.1.15.jar.index

<datasource jndi-name="java:jboss/datasources/MySqlDS" pool-name="MySqlDS" enabled="true" jta="true" use-java-context="true" use-ccm="true">

                    <connection-url>

                        jdbc:mysql://192.168.1.150:3306/hospital?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf-8

                    </connection-url>

                    <driver>

                        com.mysql

                    </driver>

                    <transaction-isolation>

                        TRANSACTION_READ_COMMITTED

                    </transaction-isolation>

                    <pool>

                        <min-pool-size>

                            10

                        </min-pool-size>

                        <max-pool-size>

                            100

                        </max-pool-size>

                        <prefill>

                            true

                        </prefill>

                        <use-strict-min>

                            false

                        </use-strict-min>

                        <flush-strategy>

                            FailingConnectionOnly

                        </flush-strategy>

                    </pool>

                    <security>

                        <user-name>

                            runes

                        </user-name>

                        <password>

                            runes

                        </password>

                    </security>

                    <statement>

                        <prepared-statement-cache-size>

                            32

                        </prepared-statement-cache-size>

                    </statement>

                </datasource>

 

 

然?後?在?<drivers>下?添?加?如?下?內?容?:

例4. mysql-connector-java-5.1.15.jar.index

<driver name="com.mysql" module="com.mysql">

                        <xa-datasource-class>

                            com.mysql.jdbc.jdbc2.optional.MysqlXADataSource

                        </xa-datasource-class>

                    </driver>

 

 

OK,這?樣?就?完?成?了?MySQL數?據?源?的?配?置?,現?在?用?standalone的?形?式?啟?動?AS7,會?看?到?輸?入?中?有?MySQL數?據?源?的?的?內?容?,如?下?圖?:

圖?片?無?法?顯?示?

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved