Currently, the connection pool of JDBC2 is only an interface and is not actually implemented. JDBC3 is under development,
It is reported that the connection pool is supported, ..........
JDBC3 uses the JNDI technology, and the configuration of the connection pool can upset a master.
Currently, the connection pool implemented by third parties is of course poolman. Version 1.0 is sufficient for general users. the configuration is also simple. Although some functions are added to version 2.0, the configuration also uses JNDI, which may be annoying for friends who do not understand RMI and EJB. we recommend that you use the 1.0 version.
If you are interested, you can also implement the connection pool. The most critical technology is to pass the connection as a parameter to a BEAN, and then return this parameter link instead of closing it.
The following is a simple implementation:
The list of DBConnectionManager. java programs is as follows:
001 import java. io .*;
002 import java. SQL .*;
003 import java. util .*;
004 import java. util. Date;
005
006 /**
007 * management class DBConnectionManager supports connection to one or more databases defined by attribute files
008 * pool access. The client program can call the getInstance () method to access the unique instance of this class.
009 */
010 public class DBConnectionManager {
011 static private DBConnectionManager instance; // unique instance
012 static private int clients;
013
014 private Vector drivers = new Vector ();
015 private PrintWriter log;
016 private Hashtable pools = new Hashtable ();
017
018 /**
019 * a unique instance is returned. If this method is called for the first time, an instance is created.
020 *
021 * @ return DBConnectionManager unique instance
022 */
023 static synchronized public DBConnectionManager getInstance (){
024 if (instance = null ){
025 instance = new DBConnectionManager ();
026}
027 clients ++;
028 return instance;
029}
030
031 /**
032 * construct a private function to prevent other objects from creating this class instance
033 */
034 private DBConnectionManager (){
035 init ();
036}
037
038 /**
039 * return the connection object to the connection pool specified by the name
040 *
041 * @ param name the connection pool name defined in the property file
042 * @ param con connection object
043 */
044 public void freeConnection (String name, Connection con ){
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