C3p0The performance of the connection pool is better than that of DBCP. hibernate recommends this connection pool. The c3p0 connection pool can not only automatically clear connections that are no longer in use, but also automatically clear statement and resultset.
Import Java. beans. propertyvetoexception; import Java. SQL. connection; import Java. SQL. resultset; import Java. SQL. sqlexception; import Java. SQL. statement; import COM. mchange. v2.c3p0. combopooleddatasource; public class c3p0_jdbc {public static void main (string [] ARGs) {combopooleddatasource DS = new combopooleddatasource (); connection conn = NULL; try {Ds. setdriverclass ("oracle. JDBC. driver. oracledriver "); DS. setjdbcurl ("JDBC: oracle: thin: @ localhost: 1521: orcl"); DS. setuser ("Scott"); DS. setpassword ("tiger"); DS. setmaxpoolsize (40); DS. setminpoolsize (2); DS. setinitialpoolsize (10); DS. setmaxstatements (100); Conn = Ds. getconnection (); // obtain the database connection through the data source statement stmt = Conn. createstatement (); resultset rs1_stmt.exe cutequery ("select * from Dept"); While (RS. next () {int deptno = Rs. getint ("deptno"); string dname = Rs. getstring ("dname"); string loc = Rs. getstring ("Loc"); system. out. println (deptno + "\ t" + dname + "\ t" + LOC);} catch (propertyvetoexception e) {e. printstacktrace ();} catch (sqlexception e) {e. printstacktrace ();} finally {try {Conn. close ();} catch (sqlexception e) {e. printstacktrace ();}}}}
public final class ComboPooledDataSource extends AbstractPoolBackedDataSource implements PooledDataSource
public interface PooledDataSource extends DataSource