You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
951 B

package com.atm.utils;
import java.sql.Connection;
import java.sql.SQLException;
import com.mchange.v2.c3p0.ComboPooledDataSource;
public class JDBCUtil {
private static ComboPooledDataSource ds = null;
public static Connection getConnection() throws SQLException{
if(ds==null) {
try {
ds=new ComboPooledDataSource();
ds.setDriverClass("com.mysql.cj.jdbc.Driver");
ds.setJdbcUrl("jdbc:mysql://localhost:3306/user?useUnicode=true&characterEncoding=utf-8&userSSL=false&serverTimezone=Asia/Shanghai");
ds.setUser("root");
ds.setPassword("123456");
ds.setMaxPoolSize(40);
ds.setMinPoolSize(2);
ds.setInitialPoolSize(5);
/*Connection conn=ds.getConnection();
conn.close();*/
}catch (Exception e) {
e.printStackTrace();
}
}
return ds.getConnection();
}
public static void main(String[] args) throws SQLException{
System.out.println(getConnection());
}
}