當(dāng)前位置:
首頁(yè) >
前端技术
> javascript
>内容正文
javascript
Spring配置内置的连接池DriverManagerDataSource
生活随笔
收集整理的這篇文章主要介紹了
Spring配置内置的连接池DriverManagerDataSource
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
applicationContext.xml配置
<?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:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"><bean id="driverManagerDateSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"><property name="driverClassName" value="com.mysql.jdbc.Driver" /><property name="url" value="jdbc:mysql:///springtest" /><property name="username" value="root" /><property name="password" value="abc"></property></bean><bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"><property name="dataSource" ref="driverManagerDateSource"></property></bean> </beans>測(cè)試
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:applicationContext.xml") public class JdbcTemplateTest2 {@Autowiredprivate JdbcTemplate jdbcTemplate;@Testpublic void test1() {// 使用JdbcTemplate來(lái)完成操作jdbcTemplate.execute("update t_user set sex='女'");// execute方法可以執(zhí)行任意sql} } 與50位技術(shù)專家面對(duì)面20年技術(shù)見證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的Spring配置内置的连接池DriverManagerDataSource的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Spring JdbcTemplate快
- 下一篇: Spring配置C3P0开源连接池