package com.ftkj.jdbc;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import javax.sql.DataSource;
import com.mchange.v2.c3p0.DataSources;
public class JdbcConnection {
final String userName;
final String password;
final String driverName;
final Map<String, Integer> property;
final String url;
DataSource ds;
{
userName = "root";
password = "123";
driverName = "com.mysql.jdbc.Driver";
url = "jdbc连接地址";
property = new HashMap();
}
public JdbcConnection() throws SQLException {
property.put("maxPoolSize", 30);
property.put("minPoolSize", 10);
property.put("checkoutTimeout", 1000*5);
property.put("idleConnectionTestPeriod", 60*10);
property.put("maxIdleTime", 60*3);
property.put("maxStatements", 100);
ds=DataSources.pooledDataSource(DataSources.unpooledDataSource(url, userName, password),property);
}
/**
* @param args
* @throws SQLException
*/
public static void main(String[] args) throws SQLException {
// TODO Auto-generated method stub
JdbcConnection con = new JdbcConnection();
Connection conn=con.ds.getConnection();
}
}
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import javax.sql.DataSource;
import com.mchange.v2.c3p0.DataSources;
public class JdbcConnection {
final String userName;
final String password;
final String driverName;
final Map<String, Integer> property;
final String url;
DataSource ds;
{
userName = "root";
password = "123";
driverName = "com.mysql.jdbc.Driver";
url = "jdbc连接地址";
property = new HashMap();
}
public JdbcConnection() throws SQLException {
property.put("maxPoolSize", 30);
property.put("minPoolSize", 10);
property.put("checkoutTimeout", 1000*5);
property.put("idleConnectionTestPeriod", 60*10);
property.put("maxIdleTime", 60*3);
property.put("maxStatements", 100);
ds=DataSources.pooledDataSource(DataSources.unpooledDataSource(url, userName, password),property);
}
/**
* @param args
* @throws SQLException
*/
public static void main(String[] args) throws SQLException {
// TODO Auto-generated method stub
JdbcConnection con = new JdbcConnection();
Connection conn=con.ds.getConnection();
}
}