老玉米:
public class DBConnhelper ,这里面封装了一个乌烟推荐的ConnectionPool
[阅读: 491] 2006-08-22 10:18:02
/**
*
*/
package bjepb.promng;
import com.softtech.jdbc.ConnectionPool;
import com.softtech.jdbc.SQLExecutor;
import com.softtech.jdbc.SQLResults;
/**
* @author Administrator
*
*/
public class DBConnhelper {
private static final int numPooledCon = 10;
private static final String driver = "com.mysql.jdbc.Driver";
private static final String url = "jdbc:mysql://localhost:3306/management";
private static final String user = "root";
private static final String password = "zhu88jie";
private static ConnectionPool conPool = null;
/**
*
*/
public DBConnhelper() {
// TODO Auto-generated constructor stub
}
private static synchronized ConnectionPool getConnectionPool()
{
if (conPool == null)
{
conPool = new ConnectionPool(numPooledCon,driver,url,user,password);
}
return conPool;
}
public static SQLResults excute(String sql)
{
conPool = getConnectionPool();
SQLExecutor sqlExec = new SQLExecutor(conPool);
SQLResults rs = sqlExec.runQuery(sql);
sqlExec.releaseConnection();
return rs;
}
public static SQLExecutor getSqlExec()
{
return new SQLExecutor(conPool);
}
}