c3po-test

導入c3p0-0.9.5.2.jar、mchange-commons-java-0.2.11.jar、mysql-connector-java-8.0.17.jarjava

 

1.c3p0-config.xml:mysql

 

<?xml version="1.0" encoding="utf-8" ?>

<c3p0-config>
<default-config>
<property name="user"></property>
<property name="password"></property>
<property name="driverClass">com.mysql.jdbc.Driver</property>
<property name="jdbcUrl">jdbc:mysql://localhost:3306</property>
</default-config>
</c3p0-config>

 

2.utils:sql

 

public class utils {    private static DataSource dataSource = new ComboPooledDataSource();    private static ThreadLocal<Connection> threadLocal = new ThreadLocal<Connection>();    public static Connection getConnection() throws SQLException {        Connection connection = threadLocal.get();        if (connection == null) {            connection = dataSource.getConnection();            threadLocal.set(connection);        }        return connection;    }}
相關文章
相關標籤/搜索
本站公眾號
   歡迎關注本站公眾號,獲取更多信息