1. Web.xml configuration file:
/ parameter>
import java.sql.CallableStatement; import java.sql.Connection; import java.sql.Date; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; import javax.naming.Context; import javax.naming.InitialContext; import javax.sql.DataSource; import util.smartDateFormat; public class dbManager { / ************************************ @Param static private bolean verbose; * @Param Statement thistatement ; * @Param preparedStatement thepstMt; * @Param connection theconnection; ****************************************************** / final static private boolean VERBOSE = true; // ??????? // static Logger logger = Logger.getLogger (dbManager.class.getName ()); private Context initCtx = null; private Context ctx = null; private DataSource DS = NULL; private statement = null; private preparedStatement thepstmt = null; / *********************************************************** ********** ??? INI TCTX * ??????? ******************************************* / publicdbmanager () { Try {INITCTX = New InitialContext (); // init concept, read config web.xmlif (INitctX == null) {throw new Exception ("Initial Failed!");} ctx = (context) INITCTX.LOOKUP ("Java: Comp / env "); // Find" JDBC / SQLServerDB "Object this configruization in the server.xml of tomcatif (CTX! = null) {DS = (Datasource) CTX.lookup (" JDBC / SQLSerVerDB ");} IF DS == NULL) {Throw new Exception ("Look Up Datasource Failed!");}}} Catch (Exception E) {log (e, "can't get the context!");}} / ***** ******************************* GET Connection * @
Return connection ******************************************************************* / public synchronizedConnection getConnection () {// Get connection and Set to delay time timelong starttime = new java.util.date (). gettime (); connection con = null; while (con == null) {con = newconnection (); if (con! = null) {// log "CREATE New Connection!"); Break;} try {log ("????, ????, ??" Timeout "MS"); wait (Timeout);} catch (interruptedException E) {log (e, "????!");} if ((NEW java.util.date (). gettime () - starttime)> = timeout) {log ("Connection Timeout!"); Break;}} return CON;} privateConnection newconnection () {connection con = null; try {con = ds.getConnection (); if (con == null) {throw new exception ("Create Connection Failed!");}} Catch (Exception E) {log ("CREATE CONNECTION FAILED!"); system.out.println (E.getMessage ());} returncon;} / ******************** ***************** Release the connection * @Param conn connection * @Param stmt statement * @Param pstmt preparedState *************** ******************************* / PUBLIC SYNCHRONIZEDVOID FREECONNECTION (C Onnection CONN, Statement Stmt, PreparedStatement PSTMT) {Try {// Close Statementif (stmt! = null) {stmt.close (); stmt = null; // log ("Close Statement ...");} // Close PreparedStatementif (PSTMT! = null) {pstmt.close (); pstmt = null; // log ("Close PreparedState ...);}} catch (Exception E) {system.out.println (E.GETMESSAGE ());} try {// close ConnectionIf (conn! = null) {conn = null; // log ("close connection ...");}} Catch (SQLEXCEPTION E) {log (e, "??????!");}} / ************************** *********** WRITE log file. * @