Access the dept table using the c3p0 connection pool

Source: Internet
Author: User
Tags dname

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.