---
title: "在spring配置jdbc-pool连接池"
author: "binbinwudi"
date: "2012-11-21T09:34:45Z"
tags: ["Spring"]
categories: ["企业架构"]
slug: "spring-jdbc-pool"
draft: false
lastmod: "2012-11-21T09:35:21Z"
id: 1731544
url: "https://binbinwudi.iteye.com/blog/1731544"
---

看了一篇文章，讲jdbc-pool比c3p0、dbcp效率高，但没有找到它在spring中的配置方式，所以自己尝试了一下，成功了。 \[code="java"] \[/code] \[code="java"] 测试代码如下 import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.logging.Level; import java.util.logging.Logger; import javax.sql.DataSource; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.FileSystemXmlApplicationContext; /\** * 简单测试jdbc-pool在spring中的配置 * @author Administrator \*/ public class JdbcPoolTest { @Test public void testPool() { ApplicationContext context = new FileSystemXmlApplicationContext("file:G:/vss/xuguang/web/WEB-INF/applicationContext.xml"); DataSource ds = (DataSource)context.getBean("dataSource"); Connection con = null; try { con = ds.getConnection(); Statement st = con.createStatement(); ResultSet rs = st.executeQuery("select top 10 personName from comm\_person"); while (rs.next()) { System.out.println("personName: " + rs.getString("personName")); } rs.close(); st.close(); } catch (SQLException ex) { Logger.getLogger(JdbcPoolTest.class.getName()).log(Level.SEVERE, null, ex); } finally { if (con != null) try {con.close();} catch (Exception ignore){} } } } \[/code] 转自http://weitd.iteye.com/blog/1497020