码迷,mamicode.com
首页 > 数据库 > 详细

spring配置数据库驱动

时间:2015-07-27 22:30:00      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:

1.利用hibernate.properties文件加载

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="locations">
    <list>
      <value>classpath:hibernate.properties</value>
    </list>
  </property>
</bean>

或者

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
  <property name="driverClassName" value="${hibernate.connection.driver_class}" />
  <property name="url" value="${hibernate.connection.url}" />
  <property name="username" value="${hibernate.connection.username}" />
  <property name="password" value="${hibernate.connection.password}" />
  <property name="initialSize" value="${hibernate.initialSize}" />
  <property name="maxActive" value="${hibernate.maxActive}" />
</bean>

hibernate.properties文件(oracle)

hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
hibernate.connection.url=jdbc\:oracle\:thin\:@127.0.0.1\:1521/abc
hibernate.connection.username=root
hibernate.connection.password=123456

hibernate.properties文件(mysql)

hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc\:mysql\://127.0.0.1\:3306/disc_shop?useUnicode\=true&characterEncoding\=utf8
hibernate.connection.username=root
hibernate.connection.password=123456


2.直接配置

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="username" value="roott"></property>
<property name="password" value="123456"></property>
<property name="url" value="jdbc:oracle:thin:@192.168.10.197:1521:abc"></property>
</bean>

spring配置数据库驱动

标签:

原文地址:http://www.cnblogs.com/JavaTWW/p/4681220.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!