Package dBc; import Java. SQL. connection; import Java. SQL. drivermanager; import Java. util. arraylist; public class databaseconnection {Private Static int maxconnectnum = 20; private Java. SQL. connection conn [] = new connection [maxconnectnum]; Private Static arraylist connectpool = new arraylist (); Private Static int flag = 0; Public databaseconnection () {If (flag = 0) {Init () ;}} private connection getconnecti Onfromdatabase () {connection trueconn = NULL; try {// class. forname ("org. gjt. mm. mySQL. driver "). newinstance (); Class. forname ("com. mySQL. JDBC. driver "). newinstance (); string url = "JDBC: mysql: // localhost: 3306/SSK? User = root & Password = dzjc & useunicode = true & characterencoding = GBK "; trueconn = drivermanager. getconnection (URL);} catch (exception ex) {system. out. println ("data connection error:" + ex. tostring ();} return trueconn;} // all connections are established here; private void Init () {for (INT I = 0; I <maxconnectnum; I ++) {conn [I] = getconnectionfromdatabase (); connectpool. add (I, Conn [I]);} flag = 1;} // obtain an available connection from the connection pool public connection getconnection () {connection conn = NULL; if (connectpool. size () = 0) {try {Java. lang. thread. sleep (1000); getconnection ();} catch (interruptedexception ex) {system. out. println ("all connections are used up. Sleep has an error. ") ;}} else {conn = (connection) connectpool. remove (0) ;}return conn ;}// provide it to external programs for calling. unused connections are put back in the connection pool... public Boolean release (connection conn) {return connectpool. add (conn);} public static void main (string [] ARGs ){}}