天天看点

spring oracle mysql_Spring连接MySQL、Oracle和SQL Server其中applicationContext.xml的配置如下:...

Spring连接MySQL、Oracle和SQL Server其中applicationContext.xml的配置如下:

&lt?xml version="1.0" encoding="UTF-8"?&gt

&ltbeans

xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"&gt

&ltbean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"&gt

&lt!-- 连接MySQL--&gt

&ltproperty name="driverClassName" value="com.mysql.jdbc.Driver"&gt&lt/property&gt

&ltproperty name="url" value="jdbc:mysql://localhost:3306/mytest"&gt&lt/property&gt

&ltproperty name="username" value="root"&gt&lt/property&gt

&ltproperty name="password" value="root"&gt&lt/property&gt

&lt!-- 连接Oracle

&ltproperty name="driverClassName" value="oracle.jdbc.driver.OracleDriver"&gt&lt/property&gt

&ltproperty name="url" value="jdbc:oracle:thin:@localhost:1521:orcl"&gt&lt/property&gt

&ltproperty name="username" value="scott"&gt&lt/property&gt

&ltproperty name="password" value="tiger"&gt&lt/property&gt

--&gt

&lt!-- 连接SQL Server

&ltproperty name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"&gt&lt/property&gt

&ltproperty name="url" value="jdbc:sqlserver://localhost:1433;databaseName=test"&gt&lt/property&gt

&ltproperty name="username" value="sa"&gt&lt/property&gt

&ltproperty name="password" value="yuji"&gt&lt/property&gt

--&gt

&ltproperty name="maxActive" value="100"&gt&lt/property&gt

&ltproperty name="maxIdle" value="30"&gt&lt/property&gt

&ltproperty name="maxWait" value="500"&gt&lt/property&gt

&ltproperty name="defaultAutoCommit" value="true"&gt&lt/property&gt

&lt/bean&gt

&ltbean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt

&ltproperty name="dataSource" ref="dataSource"&gt&lt/property&gt

&ltproperty name="hibernateProperties"&gt

&ltprops&gt

&lt!-- MySQL的方言--&gt

&ltprop key="hibernate.dialect"&gtorg.hibernate.dialect.MySQLDialect&lt/prop&gt

&lt!-- Oracle的方言

&ltprop key="hibernate.dialect"&gtorg.hibernate.dialect.OracleDialect&lt/prop&gt

--&gt

&lt!-- SQL Server的方言

&ltprop key="hibernate.dialect"&gtorg.hibernate.dialect.SQLServerDialect&lt/prop&gt

--&gt

&ltprop key="hibernate.show_sql"&gttrue&lt/prop&gt

&lt/props&gt

&lt/property&gt

&ltproperty name="mappingResources"&gt

&ltlist&gt

&ltvalue&gtcom/test/bean/User.hbm.xml&lt/value&gt

&lt/list&gt

&lt/property&gt

&lt/bean&gt

&ltbean id="userDao" class="com.test.dao.impl.UserDAOImpl" scope="singleton"&gt

&ltproperty name="sessionFactory"&gt

&ltref bean="sessionFactory"/&gt

&lt/property&gt

&lt/bean&gt

&ltbean id="userService" class="com.test.service.impl.UserServiceImpl"&gt

&ltproperty name="userDao" ref="userDao"&gt&lt/property&gt

&lt/bean&gt

&ltbean id="saveUserAction" class="com.test.action.user.SaveUserAction" scope="prototype"&gt

&ltproperty name="service" ref="userService"&gt&lt/property&gt

&lt/bean&gt

&ltbean id="listUserAction" class="com.test.action.user.ListUserAction" scope="prototype"&gt

&ltproperty name="service" ref="userService"&gt&lt/property&gt

&lt/bean&gt

&ltbean id="removeUserAction" class="com.test.action.