package cn.lijun.demo; import com.mchange.v2.c3p0.ComboPooledDataSource; import javax.sql.DataSource; import java.sql.Connection; import java.sql.SQLException; public class Demo2C3p0 { public static void main(String[] args) { try { //获得连接池的容器 DataSource DataSource ds=new ComboPooledDataSource(); //打印所得的连接对象 配置文件中最大是10,关闭一个就能还回去一个,然后可以被立即调用 for(int i=1;i<=11;i++){ Connection conn = ds.getConnection(); System.out.println(i+" "+conn); if(i==5){ conn.close(); } } } catch (SQLException e) { e.printStackTrace(); } } }