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 boolean VERBOSE ;
* @param Statement theStatement;
* @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 long timeout = 5000;
private Statement theStatement = null;
private PreparedStatement thePstmt = null;
/************************************
* 初试化initCtx
* 取得数据源对象
************************************/
public
dbManager() {
try {
initCtx = new InitialContext();
//init context,read config web.xml
if (initCtx == null) {
throw new Exception("Initial Failed!");
}
ctx = (Context) initCtx.lookup("java:comp/env");
//find "jdbc/SqlServerDB" object this configruation in the SERVER.XML of Tomcat
if (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 synchronized
Connection getConnection
| 对此文章发表了评论 |
