歐陽良才

          不是別人,就是我陽良才
          隨筆 - 13, 文章 - 8, 評論 - 2, 引用 - 0

          導航

          <2012年4月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          公告

          人生不能沒有朋友

          常用鏈接

          留言簿

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          SSi(spring+struts_ibatis)多數據庫連接解決方案

          1。創建配置文件 jdbc.properties

          jdbc.driverClassName=com.mysql.jdbc.Driver
          jdbc.url
          =jdbc:mysql://192.168.99.100/infodata?useUnicode=true&amp;characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true
          jdbc.username=root
          jdbc.password
          =root
          jdbc2.driverClassName
          =com.mysql.jdbc.Driver
          jdbc2.url
          =jdbc:mysql://192.168.99.101/data1?useUnicode=true&amp;characterEncoding=utf-8
          jdbc2.username=root
          jdbc2.password
          =root
          jdbc3.driverClassName
          =com.mysql.jdbc.Driver
          jdbc3.url
          =jdbc:mysql://192.168.99.102/data2?useUnicode=true&amp;characterEncoding=utf-8
          jdbc3.username=root
          jdbc3.password
          =root 

          2。在spring配置文件中寫入

          <?xml version="1.0" encoding="UTF-8"?>
          <beans
           xmlns
          ="http://www.springframework.org/schema/beans"
           xmlns:xsi
          ="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:aop
          ="http://www.springframework.org/schema/aop"
           xmlns:tx
          ="http://www.springframework.org/schema/tx"
           
           xsi:schemaLocation
          ="http://www.springframework.org/schema/beans 
             http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
             http://www.springframework.org/schema/context/spring-context-2.5.xsd
                  http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
                     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
          <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
          <property name="locations">
              
          <list>
                
          <value>classpath:jdbc.properties</value>
              
          </list>
          </property>
          </bean>
           
          <!-- =========================transactionManager========================= -->
          <bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
          <property name="beanNames">
              
          <value>dao*</value>
          </property>
          <property name="interceptorNames">
              
          <list>
                
          <value>transactionInterceptor</value>
                 
          <value>transactionInterceptor2</value>
              
          </list>
          </property>
          </bean>
          <!-- ========================= dataSource1========================= -->
          <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
             
          <property name="driverClassName" value="${jdbc.driverClassName}"/>
             
          <property name="url" value="${jdbc.url}&amp;characterEncoding=utf-8"/>
             
          <property name="username" value="${jdbc.username}"/>
             
          <property name="password" value="${jdbc.password}"/>
          </bean>
                 
          <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
             
          <property name="dataSource" ref="dataSource"/>
          </bean>
                
          <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
             
          <property name="transactionManager" ref="transactionManager"/>
                          
          <property name="transactionAttributes">
                          
          <props>
                          
          <prop key="insert*">PROPAGATION_REQUIRED</prop>
                          
          <prop key="delete*">PROPAGATION_REQUIRED</prop>
                          
          <prop key="update*">PROPAGATION_REQUIRED</prop>
                          
          <prop key="get*">PROPAGATION_REQUIRED</prop>
                           
          </props>
                          
          </property>
          </bean>
          <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
             
          <property name="configLocation">
             
          <value>classpath:SqlMapConfig.xml</value>
             
          </property>
             
          <property name="dataSource" ref="dataSource"/>
          </bean>
          <!-- ========================= dataSource2========================= -->
             
          <bean id="dataSource2" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
             
          <property name="driverClassName" value="${jdbc2.driverClassName}"/>
             
          <property name="url" value="${jdbc2.url}&amp;characterEncoding=utf-8"/>
             
          <property name="username" value="${jdbc2.username}"/>
             
          <property name="password" value="${jdbc2.password}"/>
          </bean>
              
          <bean id="transactionManager2" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
             
          <property name="dataSource" ref="dataSource2"/>
          </bean>
          <bean id="transactionInterceptor2" class="org.springframework.transaction.interceptor.TransactionInterceptor">
             
          <property name="transactionManager" ref="transactionManager2"/>
                          
          <property name="transactionAttributes">
                          
          <props>
                          
          <prop key="insert*">PROPAGATION_REQUIRED</prop>
                          
          <prop key="delete*">PROPAGATION_REQUIRED</prop>
                          
          <prop key="update*">PROPAGATION_REQUIRED</prop>
                          
          <prop key="get*">PROPAGATION_REQUIRED</prop>
                           
          </props>
                          
          </property>
          </bean>
             
          <bean id="sqlMapClient2" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
             
          <property name="configLocation">
             
          <value>classpath:SqlMapConfig2.xml</value>
             
          </property>
             
          <property name="dataSource" ref="dataSource2"/>
          </bean>
          <!-- ========================= dataSource3========================= -->
             
          <bean id="dataSource3" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
             
          <property name="driverClassName" value="${jdbc3.driverClassName}"/>
             
          <property name="url" value="${jdbc3.url}&amp;characterEncoding=utf-8"/>
             
          <property name="username" value="${jdbc3.username}"/>
             
          <property name="password" value="${jdbc3.password}"/>
          </bean>
              
          <bean id="transactionManager3" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
             
          <property name="dataSource" ref="dataSource3"/>
          </bean>
          <bean id="transactionInterceptor3" class="org.springframework.transaction.interceptor.TransactionInterceptor">
             
          <property name="transactionManager" ref="transactionManager3"/>
                          
          <property name="transactionAttributes">
                          
          <props>
                          
          <prop key="insert*">PROPAGATION_REQUIRED</prop>
                          
          <prop key="delete*">PROPAGATION_REQUIRED</prop>
                          
          <prop key="update*">PROPAGATION_REQUIRED</prop>
                          
          <prop key="get*">PROPAGATION_REQUIRED</prop>
                           
          </props>
                          
          </property>
          </bean>
             
          <bean id="sqlMapClient3" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
             
          <property name="configLocation">
             
          <value>classpath:SqlMapConfig3.xml</value>
             
          </property>
             
          <property name="dataSource" ref="dataSource3"/>
          </bean>

                
           
          </beans>

           3。導入兩個jar包:

          c3p0-0.9.1.2.jar
          commons-pool.jar
          commons-dbcp.jar

          此文章來自 wing123 詳情http://wing123.iteye.com/blog/1350194

          posted on 2012-04-07 15:52 歐陽良才 閱讀(1633) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 新河县| 海林市| 建德市| 清河县| 汉源县| 桃江县| 芜湖县| 林芝县| 兰西县| 舞阳县| 库尔勒市| 桃江县| 娄烦县| 潜山县| 林州市| 汉川市| 台江县| 红原县| 苍梧县| 九江县| 三河市| 广汉市| 平原县| 台州市| 晋宁县| 黄冈市| 澎湖县| 衡山县| 凌海市| 方城县| 西藏| 丰县| 富民县| 塘沽区| 平潭县| 株洲市| 阳西县| 成都市| 广州市| 宜昌市| 建阳市|