What is a connection pool?

0 votes
103 views
Sunita  Singh asked 14-Nov-2017 in programming by Sunita Singh

What is a connection pool?

1 Answer

0 votes
Arti Mishra answered 15-Sep-2018 by Arti Mishra

“Connection Pool” 

Connection Pool is the cache of a database, which maintain the connection when we reused future requests. Generally, it is used for increasing the performance of executing commands on a database. In connection pooling, when the connection is created, it is placed in the pool and reused again before establishing new connections. 

"Connection Pool Architecture"
What is a connection pool?


JDBC Connection Pooling Scope:

import java.sql.*;
public class JDBCServlet extends HttpServlet { 
    private Connection connection; 
    public void init(ServletConfig c) throws ServletException { 
       ……………..
     …………….. // write some code for Open the connection
     ………………….
    }
    public void destroy() {
   ………………………..
    …………………. //write some code for Close the connection
    }
    public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException {
    ……………..
     ………….. //Use the connection here
      Statement stmt = connection.createStatement();
      …………………..
…………………. // perform JDBC Work
…………………
  }
}