Package CN. secondteam. utils; import Java. beans. propertyvetoexception; import Java. SQL. connection; import Java. SQL. preparedstatement; import Java. SQL. resultset; import Java. SQL. sqlexception; import Java. SQL. statement; import COM. mchange. v2.c3p0. combopooleddatasource; public class dbutil {final static string host = "127.0.0.1"; Final Static string name = "root"; Final Static string psw = "root"; static final St Ring dbname = "bbsdb"; Private Static connection; public static combopooleddatasource dswebgame; static {dswebgame = new combopooleddatasource (); try {dswebgame. setdriverclass (driver);} catch (propertyvetoexception e) {e. printstacktrace ();} // The parameter is read by the config class according to the configuration file. setjdbcurl (URL); // set the database logon username dswebgame. setuser (username); // set the password of the database logon user dswebgame. setpassword (password );// Set the maximum number of connections in the connection pool dswebgame. setmaxpoolsize (35); // set the minimum number of connections in the connection pool dswebgame. setminpoolsize (20); // sometimes a deadlock occurs. Set maxstatements to 0 dswebgame. setmaxstatements (0); // wait timeout smaller than MySQL. Dswebgame. setidleconnectiontestperiod (120);}/*** get database connection ** @ return */public static connection getconnection () {If (null = connection) {connection = newconnection ();} Try {If (connection. isclosed () {connection = dswebgame. getconnection () ;}} catch (sqlexception e) {e. printstacktrace ();} return connection;}/*** create a database connection * @ return */Private Static connection newconnection () {try {return (Conn Ection) dswebgame. getconnection ();} catch (sqlexception e) {e. printstacktrace (); return NULL ;}} public static void main (string ARGs []) {getconnection ();} /*** release resources ** @ Param conn * @ Param st * @ Param RS */public static void release (connection con, statement St, resultset RS) {If (RS! = NULL) {try {Rs. Close () ;}catch (exception e) {e. printstacktrace () ;}rs = NULL ;}if (st! = NULL) {try {st. Close () ;}catch (exception e) {e. printstacktrace () ;}} if (con! = NULL) {try {con. Close () ;}catch (exception e) {e. printstacktrace ();}}}}