Spring配置数据库(mysql,oracle)

时间:2014-05-09 03:02:38   收藏:0   阅读:322
bubuko.com,布布扣
bubuko.com,布布扣
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" >
    <property name="driverClassName">
    <!--<value>com.microsoft.sqlserver.jdbc.SQLServerDriver</value>-->
    <value>com.mysql.jdbc.Driver</value>
    </property>
    <property name="url">
        <!-- <value>jdbc:sqlserver://192.168.2.186:1433;DatabaseName=test2013</value> -->
        <value>jdbc:mysql://127.0.0.1:3306/ssh4</value>
    </property>
    <property name="username">
        <value>root</value>
    </property>
    <property name="password">
        <value>root</value>    
    </property>
    </bean>
    
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <!-- 数据源的设定 -->
    <property name="dataSource">
    <ref local="dataSource"/>
    </property>
    <property name="mappingResources">
        <list>
            <value>com/zhangyue/bean/ZYCStudent.hbm.xml</value>
            <value>com/zhangyue/bean/ZYCCourse.hbm.xml</value>
            <value>com/zhangyue/bean/ZYCStudentCourse.hbm.xml</value>
            <value>com/zhangyue/bean/ZYCStudentFile.hbm.xml</value>
        </list>
    </property>
    
    <property name="hibernateProperties">
    <props>
        <prop key="hibernate.dialect">
        <!--org.hibernate.dialect.SQLServerDialect-->
        org.hibernate.dialect.MySQLDialect
        </prop>
        <prop key="hibernate.hbm2ddl.auto">update</prop>  
        <prop key="hibernate.show_sql">true</prop>
    </props>
    </property>
    </bean>
bubuko.com,布布扣
bubuko.com,布布扣

上面是MySQL版本(SQLServer版本):

下面是Oracle版本:


 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" >
 <property name="driverClassName">
 <value>oracle.jdbc.driver.OracleDriver</value>
 </property>
 <property name="url">
  <value>jdbc:oracle:thin:@192.168.1.21:1521:orcl</value>
 </property>
 <property name="username">
  <value>test</value>
 </property>
 <property name="password">
  <value>test</value> 
 </property>
 </bean>
 
 <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
 <!-- 数据源的设定 -->
 <property name="dataSource">
 <ref local="dataSource"/>
 </property>
 <property name="mappingResources">
  <list>
   <value>com/test/bean/User.hbm.xml</value>
  </list>
 </property>
 
 <property name="hibernateProperties">
 <props>
  <prop key="hibernate.dialect">
   org.hibernate.dialect.OracleDialect
  </prop>
  <prop key="hibernate.show_sql">
   true
  </prop>
 </props>
 </property>
 </bean>

Spring配置数据库(mysql,oracle),布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!