How to establish a connection pool in JDBC?

前端 未结 13 2558
一个人的身影
一个人的身影 2020-11-22 02:43

Can anybody provide examples or links on how to establish a JDBC connection pool?

From searching google I see many different ways of doing this and it is rather conf

13条回答
  •  日久生厌
    2020-11-22 03:11

    I would recommend using the commons-dbcp library. There are numerous examples listed on how to use it, here is the link to the move simple one. The usage is very simple:

     BasicDataSource ds = new BasicDataSource();
     ds.setDriverClassName("oracle.jdbc.driver.OracleDriver")
     ds.setUsername("scott");
     ds.setPassword("tiger");
     ds.setUrl(connectURI);
     ...
     Connection conn = ds.getConnection();
    

    You only need to create the data source once, so make sure you read the documentation if you do not know how to do that. If you are not aware of how to properly write JDBC statements so you do not leak resources, you also might want to read this Wikipedia page.

提交回复
热议问题