查看: 489|回复: 2

jboss配置 mysql数据库连接池实例

 关闭 [复制链接]

签到天数: 2090 天

连续签到: 2 天

[LV.Master]伴坛终老IIII

发表于 2009-7-18 22:03 | 显示全部楼层 |阅读模式
jboss配置 mysql数据库连接池实例
1 :配置:
JDK 1.5
JBoss4.0.4
Mysql5.0
Myeclipse 4.1
2:建立数据库:
create database test;
use test;
DROP TABLE IF EXISTS `test`;
CREATE TABLE `test` (
`Test_id` int(11) NOT NULL auto_increment,
`Test_name` varchar(45) NOT NULL default '',
`Test_password` varchar(45) NOT NULL default '',
PRIMARY KEY(`Test_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `test` VALUES (1,'test','test'),(2,'test2','test');
3:Copy MySQL的JDBC驱动放到jboss-4.0.4\\server\\default\\lib
可到MYsql网站下载www.mysql.com
4:在 jboss-4.0.4\\server\\default\\deploy下新建文件mysql-ds.xml
可从jboss-4.0.4\\docs\\examples\\jca copy 修改
想配置多个连接池只要多加一个<local-tx-datasource></local-tx-datasource>
其中内容如下:
<?xml version=\"1.0\" encoding=\"UTF-8\"?>

<!-- $Id: mysql-ds.xml,v 1.3.2.3 2006/02/07 14:23:00 acoliver Exp $ -->
<!--Datasource config for MySQL using 3.0.9 available from:
http://www.mysql.com/downloads/api-jdbc-stable.html
-->
<datasources>
<local-tx-datasource>
<jndi-name>test</jndi-name>
<connection-url>jdbc:mysql://127.0.0.1:3306/test</connection-url><!?test为数据库名-->

<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>root</user-name><!?用户名以下相同-->
<password>xxxxxxxx</password><!?密码以下相同-->

<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
<!-- should only be used on drivers after 3.22.1 with \"ping\" support
<valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
-->
<!-- sql to call when connection is created
<new-connection-sql>some arbitrary sql</new-connection-sql>
-->
<!-- sql to call on an existing pooled connection when it is obtained from pool - MySQLValidConnectionChecker is preferred for newer drivers
<check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
-->

<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>

5:修改jboss-4.0.4\\server\\default\\conf\\ standardjaws.xml
<jaws>
<datasource>java:/test</datasource>
<type-mapping>mySql</type-mapping>
.....
</jaws>
修改jboss-4.0.4\\server\\default\\conf\\ standardjbosscmp-jdbc.xml
<jbosscmp-jdbc>
<defaults>
<datasource>java:/test</datasource>
<datasource-mapping>mySql</datasource-mapping>
</defaults>
</jbosscmp-jdbc>
修改jboss-4.0.4\\server\\default\\conf\\ login-config.xml
<application-policy name = \"MySqlDbRealm\">

<authentication>

<login-module code =

\"org.jboss.resource.security.ConfiguredIdentityLoginModule\"

flag = \"required\">

<module-option name =\"principal\">test</module-option>

<module-option name =\"userName\">root</module-option>

<module-option name =\"password\"
PCOS系统下载站:http://zhuangji.wang

签到天数: 2090 天

连续签到: 2 天

[LV.Master]伴坛终老IIII

 楼主| 发表于 2009-7-18 22:03 | 显示全部楼层

jboss配置 mysql数据库连接池实例

jboss配置 mysql数据库连接池实例
1 :配置:
JDK 1.5
JBoss4.0.4
Mysql5.0
Myeclipse 4.1
2:建立数据库:
create database test;
use test;
DROP TABLE IF EXISTS `test`;
CREATE TABLE `test` (
`Test_id` int(11) NOT NULL auto_increment,
`Test_name` varchar(45) NOT NULL default &#39;&#39;,
`Test_password` varchar(45) NOT NULL default &#39;&#39;,
PRIMARY KEY(`Test_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `test` VALUES (1,&#39;test&#39;,&#39;test&#39;),(2,&#39;test2&#39;,&#39;test&#39;);
3:Copy MySQL的JDBC驱动放到jboss-4.0.4\\server\\default\\lib
可到MYsql网站下载www.mysql.com
4:在 jboss-4.0.4\\server\\default\\deploy下新建文件mysql-ds.xml
可从jboss-4.0.4\\docs\\examples\\jca copy 修改
想配置多个连接池只要多加一个<local-tx-datasource></local-tx-datasource>
其中内容如下:
<?xml version=\"1.0\" encoding=\"UTF-8\"?>

<!-- $Id: mysql-ds.xml,v 1.3.2.3 2006/02/07 14:23:00 acoliver Exp $ -->
<!--Datasource config for MySQL using 3.0.9 available from:
http://www.mysql.com/downloads/api-jdbc-stable.html
-->
<datasources>
<local-tx-datasource>
<jndi-name>test</jndi-name>
<connection-url>jdbc:mysql://127.0.0.1:3306/test</connection-url><!?test为数据库名-->

<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>root</user-name><!?用户名以下相同-->
<password>xxxxxxxx</password><!?密码以下相同-->

<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
<!-- should only be used on drivers after 3.22.1 with \"ping\" support
<valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
-->
<!-- sql to call when connection is created
<new-connection-sql>some arbitrary sql</new-connection-sql>
-->
<!-- sql to call on an existing pooled connection when it is obtained from pool - MySQLValidConnectionChecker is preferred for newer drivers
<check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
-->

<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>

5:修改jboss-4.0.4\\server\\default\\conf\\ standardjaws.xml
<jaws>
<datasource>java:/test</datasource>
<type-mapping>mySql</type-mapping>
.....
</jaws>
修改jboss-4.0.4\\server\\default\\conf\\ standardjbosscmp-jdbc.xml
<jbosscmp-jdbc>
<defaults>
<datasource>java:/test</datasource>
<datasource-mapping>mySql</datasource-mapping>
</defaults>
</jbosscmp-jdbc>
修改jboss-4.0.4\\server\\default\\conf\\ login-config.xml
<application-policy name = \"MySqlDbRealm\">

<authentication>

<login-module code =

\"org.jboss.resource.security.ConfiguredIdentityLoginModule\"

flag = \"required\">

<module-option name =\"principal\">test</module-option>

<module-option name =\"userName\">root</module-option>

<module-option name =\"password\"
PCOS系统下载站:http://zhuangji.wang

签到天数: 2090 天

连续签到: 2 天

[LV.Master]伴坛终老IIII

 楼主| 发表于 2009-7-18 22:03 | 显示全部楼层

jboss配置 mysql数据库连接池实例

jboss配置 mysql数据库连接池实例
1 :配置:
JDK 1.5
JBoss4.0.4
Mysql5.0
Myeclipse 4.1
2:建立数据库:
create database test;
use test;
DROP TABLE IF EXISTS `test`;
CREATE TABLE `test` (
`Test_id` int(11) NOT NULL auto_increment,
`Test_name` varchar(45) NOT NULL default &#39;&#39;,
`Test_password` varchar(45) NOT NULL default &#39;&#39;,
PRIMARY KEY(`Test_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `test` VALUES (1,&#39;test&#39;,&#39;test&#39;),(2,&#39;test2&#39;,&#39;test&#39;);
3:Copy MySQL的JDBC驱动放到jboss-4.0.4\\server\\default\\lib
可到MYsql网站下载www.mysql.com
4:在 jboss-4.0.4\\server\\default\\deploy下新建文件mysql-ds.xml
可从jboss-4.0.4\\docs\\examples\\jca copy 修改
想配置多个连接池只要多加一个<local-tx-datasource></local-tx-datasource>
其中内容如下:
<?xml version=\"1.0\" encoding=\"UTF-8\"?>

<!-- $Id: mysql-ds.xml,v 1.3.2.3 2006/02/07 14:23:00 acoliver Exp $ -->
<!--Datasource config for MySQL using 3.0.9 available from:
http://www.mysql.com/downloads/api-jdbc-stable.html
-->
<datasources>
<local-tx-datasource>
<jndi-name>test</jndi-name>
<connection-url>jdbc:mysql://127.0.0.1:3306/test</connection-url><!?test为数据库名-->

<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>root</user-name><!?用户名以下相同-->
<password>xxxxxxxx</password><!?密码以下相同-->

<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
<!-- should only be used on drivers after 3.22.1 with \"ping\" support
<valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
-->
<!-- sql to call when connection is created
<new-connection-sql>some arbitrary sql</new-connection-sql>
-->
<!-- sql to call on an existing pooled connection when it is obtained from pool - MySQLValidConnectionChecker is preferred for newer drivers
<check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
-->

<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>

5:修改jboss-4.0.4\\server\\default\\conf\\ standardjaws.xml
<jaws>
<datasource>java:/test</datasource>
<type-mapping>mySql</type-mapping>
.....
</jaws>
修改jboss-4.0.4\\server\\default\\conf\\ standardjbosscmp-jdbc.xml
<jbosscmp-jdbc>
<defaults>
<datasource>java:/test</datasource>
<datasource-mapping>mySql</datasource-mapping>
</defaults>
</jbosscmp-jdbc>
修改jboss-4.0.4\\server\\default\\conf\\ login-config.xml
<application-policy name = \"MySqlDbRealm\">

<authentication>

<login-module code =

\"org.jboss.resource.security.ConfiguredIdentityLoginModule\"

flag = \"required\">

<module-option name =\"principal\">test</module-option>

<module-option name =\"userName\">root</module-option>

<module-option name =\"password\"
PCOS系统下载站:http://zhuangji.wang

本版积分规则