Connection Pool Implementation
In the implementation in this article, a connection pool is a class with a number of JDBC
objects and access methods. You could also think of it as a container with a simple interface for controlling and managing database connections. To execute a SQL request, get data from the database, or change the data, open a database connection and get an object of
type. You will process all subsequent operations with this object. You can specify the size of your connection pool according to your available resources.
SimpleConnectionPool, realizes a connection pool. It's comprised of a limited set of methods for database connection. In each case, functionality and class realization will vary depending on the existing task. This implementation acts as a basic skeleton for a connections storehouse.
The connection pool will do the following:
- Enable a load-specific database driver for each database;
- Get the reference to the
SimpleConnectionPool object, which represents a connection pool exactly;
- Get an available connection (of
Connection type) from your storehouse;
- Put a connection back into the storehouse;
- Free all resources and closes all opened connections in your storehouse
Different implementations of a JDBC connection pool exist in different utility packages and frameworks (for example, the Jakarta Struts framework has
SimpleConnectionPool class represents a uniform connections storehouse to a previously specified database. You need at least three arguments to access a database: the URL ID of the database, a user login, and a password. The URL ID consists of a protocol ID, a driver ID, and a database ID. The protocol ID is always
jdbc, the driver ID could be
mysql, etc., and the database ID depends only on the implementation of the database driver. For example, the URL ID "
jdbc:odbc:test" can be used for database access via a JDBC-ODBC bridge, and the URL ID "
jdbc:mysql:localhost/test" can be used to access a MySQL test database on localhost (some MySQL driver implementations require you to specify a user access login/password in the URL ID).