package cn.dzj.demo.jdbc.datasource;
import java.sql.*;
import java.util.LinkedList;
/**
* Create Date:2013-7-16 Author : Dzj E-mail : 625065470@qq.com
*/
public class MyDataSource {
public static String url = "jdbc:mysql://localhost:3306/PIMS";
public static String username = "root";
public static String password = "123456";
private LinkedList<Connection> connectionPool = new LinkedList<Connection>();
//初始化10个连接数
public MyDataSource() throws SQLException {
for (int i = 0; i < 10; i++) {
this.connectionPool.addLast(this.createConnection());
}
}
public Connection createConnection() throws SQLException {
return DriverManager.getConnection(url, username, password);
}
//获取连接
public Connection getConnection()
{
return this.connectionPool.removeFirst();
}
//释放连接
public void free(Connection conn)
{
this.connectionPool.addLast(conn);
}
}
jdbc之连接池
最新推荐文章于 2024-09-30 11:02:27 发布