c3p0连接池,改造JDBCUtils工具类

使用c3p0连接池,改造JDBCUtils工具类,需要导入数据库驱动包和c3p0连接池相关jar包

以下是代码片段:

import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;

import com.mchange.v2.c3p0.ComboPooledDataSource;

/**
 * JDBC的工具类:
 * @author admin
 *
 */
public class JDBCUtils {
	private static final ComboPooledDataSource DATA_SOURCE =new ComboPooledDataSource();
	/**
	 * 获得连接的方法
	 */
	public static Connection getConnection(){
		Connection conn = null;
		try {
			conn = DATA_SOURCE.getConnection();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return conn;
	}
	
	public static DataSource getDataSource(){
		return DATA_SOURCE;
	}
	
}

你可能感兴趣的:(JDBC,c3p0,JDBCUtils)