Spring配置文件中配置数据库连接(mysql,sqlserver,oracle)

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Prety_Boy/article/details/53611601

xml配置文件中配置如下:

<spring:bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<spring:property name="locations">
<spring:list>
<spring:value>classpath:conf/jdbc.properties</spring:value>
</spring:list>
</spring:property>
</spring:bean>

<spring:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<spring:property name="driverClassName"
value="${jdbc.driverClassName}" />
<spring:property name="url"
value="${jdbc.url}" />
<spring:property name="username" value="${jdbc.username}" />
<spring:property name="password" value="${jdbc.password}" />
<spring:property name="maxActive" value="30" />
<spring:property name="maxIdle" value="10" />
<spring:property name="maxWait" value="1000" />
<spring:property name="defaultAutoCommit" value="true" />
</spring:bean> 

jdbc.properties配置文件中连接数据库配置:

#sqlserver数据源配置
jdbc.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.url=jdbc:sqlserver://192.168.1.60:1408;DatabaseName=test
jdbc.username=sa
jdbc.password=1

#mysql数据源配置
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://192.168.1.60:3306/test
jdbc.username=root
jdbc.password=root

#Oracle数据源配置
jdbc.driverClassName=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc:oracle:thin:@10.60.17.9:1521:orcl
jdbc.username=admin
jdbc.password=admin 



展开阅读全文

没有更多推荐了,返回首页