You say it's a database connection pool. That's the connection to the database. JDBC is a Java-encapsulated operation on a database. Of course you can further encapsulate yourself. Database connection pooling is a prerequisite for JDBC, and if the database connection pool is not connected, the JDBC operation is not available. and the database connection pool of light is useless ah, you connected to the database does not operate it is not a white company. So we need JDBC.
Has not been clear, JDBC data source and connection pool is how the same relationship, until today when the system, encountered a connection pool if the management of effective connection and resource occupancy, the issue of release.
The data source is not equal to the connection pool, it is not required to implement a connection pool, that is, a connection pool is one of the data sources. The following online summary can be used to substantiate:
A basic datasource implementation that does not implement a connection pool, typically, is provided by the JDBC driver vendor. In the basic DataSource implementation, the following is true:
- DataSource?. The Getconnection method creates a new Connection object that represents a physical connection and encapsulates all installation and management work for that connection.
- The Connection.close method closes the physical connection and frees the associated resource.
In the DataSource implementation, which includes connection pooling, there are a number of significant events that occur behind the scenes. In the implementation as above, the following is true:
- datasource ? The implementation includes an implementation of the specified connection pool module that manages a buffer of Pooledconnection objects. The DataSource object is typically implemented by the application server as a layer in the top layer of the driver implementation of the ConnectionPoolDataSource and Pooledconnection interfaces.
- datasource ?. Getconnection calls the Pooledconnection.getconnection method to obtain a logical handle to the specified physical connection. The cost of establishing a new physical connection occurs only if there are no connections available in the connection pool. When a new physical connection is required, the connection pool manager calls ConnectionPoolDataSource's Getpooledconnection method to create one. The work of managing physical connections is handled by the Pooledconnection object agent. The
- Connection.close method closes the logical handle, but the physical connection also exists. The connection pool Manager is notified that the specified Pooledconnection object can now be reused. If an application attempts to reuse a logical handle, the connection implementation throws a SqlException.
- A single physical Pooledconnection object produces many logical connection objects during the lifetime. For a given Pooledconnection object, only the newly generated logical connection object is valid. When the associated pooledconnection.getconnection is called, any previously existing connection objects are automatically closed. The Listener (Connection pool manager) is not notified of the event.
- A connection pool manager shuts down physical connections by calling the Pooledconnection.close method. This method is typically only called in a specific environment: when the application server encounters a normal shutdown when the connection buffer is being reinitialized, or when the application server receives an event indicating that the connection has an unrecoverable error.
Should be shut down after using conection and statement, or it will cause the database cursor usage to exceed the limit because the garbage collector cannot effectively release the resource. A SqlException exception occurs. So don't put createstatement and preparestatement on the outside of the loop when using JDBC later, and use these statment to close them in time. It is best to close the statment immediately after performing a executequery, executeupdate, and so on, if you do not need to use the result set (ResultSet) data.
About JDBC and database connection pooling relationships (not encapsulated relationships)