在JBoss数据源中,如何为数据库故障转移提供多个连接字符串,以供我使用。Jboss数据源中的数据库故障转移
将有两个具有相同表格的Mysql数据库说DB1和DB2。我想将数据插入到DB1,如果DB1关闭,那么我需要将它插入到DB2中。在DB1出现时插入到DB2期间,我需要将其余数据插入到DB1中。我怎样才能在我的JBoss中进行配置?
在JBoss数据源中,如何为数据库故障转移提供多个连接字符串,以供我使用。Jboss数据源中的数据库故障转移
将有两个具有相同表格的Mysql数据库说DB1和DB2。我想将数据插入到DB1,如果DB1关闭,那么我需要将它插入到DB2中。在DB1出现时插入到DB2期间,我需要将其余数据插入到DB1中。我怎样才能在我的JBoss中进行配置?
<?xml version="2.0" encoding="UTF-8"?>
<!-- $Id$ -->
<!-- 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>MySqlDSTest</jndi-name>
<use-java-context>true</use-java-context>
<connection-url>jdbc:mysql:loadbalance://ip1,ip2:3306/dbname?</connection-url>
<url-delimiter>|</url-delimiter>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<connection-property name="readOnly">false</connection-property>
<autoReconnect>true</autoReconnect>
<failOverReadOnly>false</failOverReadOnly>
<user-name>userName</user-name>
<password>password</password>
<check-valid-connection-sql>selcect count(*) from TEST_TAB</check-valid-connection-sql>
<maxReconnects>0</maxReconnects>
<initialTimeout>15</initialTimeout>
<idle-timeout-minutes>0</idle-timeout-minutes>
<valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
<!-- Advanced options for the MySQL Driver can be set with
<connection-property name="property">value</connection-property>
-->
<min-pool-size>5</min-pool-size>
<!-- Don't set this any higher than max_connections on your
MySQL server, usually this should be a 10 or a few 10's
of connections, not hundreds or thousands -->
<max-pool-size>20</max-pool-size>
<!-- Don't allow connections to hang out idle too long,
never longer than what wait_timeout is set to on the
server...A few minutes is usually okay here,
it depends on your application
and how much spikey load it will see -->
<!-- If you're using Connector/J 3.1.8 or newer, you can use
our implementation of these to increase the robustness
"mysql-ds.xml" 64L, 3683C of the connection pool. -->
<exception-sorter-class-name>
com.mysql.jdbc.integration.jboss.ExtendedMysqlExceptionSorter
</exception-sorter-class-name>
<valid-connection-checker-class-name>
com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker
</valid-connection-checker-class-name>
<!-- sql to call when connection is created -->
<new-connection-sql>select 1</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>
select 1
</check-valid-connection-sql>
<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml -->
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
这第二个数据库catch块本身的连接将对于JBoss测绘工作
如果您省略
请按照此文档。 Jboss有配置设置。 https://community.jboss.org/wiki/JBossJCADatabaseFailover
此外,如果您不使用JNDI和滑动JDBC调用我甲肝另一个解决方案 - 假设你是一个JDBC调用,那么你将需要获得一个数据库连接,如果DB是下跌,那么你将得到数据库连接异常,在try catch块,如果遇到连接异常,创建:-)
您可能需要设置一个合适的MySQL集群:http://dev.mysql.com/doc/refman/5.1/en/mysql-cluster-replication-failover。 html – home 2012-02-23 08:02:35