📄 connmanager.java
字号:
package bbs;
import java.sql.*;
import java.util.*;
public class ConnManager {
private Vector PoolNames = new Vector();
private Vector DriverNames = new Vector();
private Vector DbIds = new Vector();
private Vector UserNames = new Vector();
private Vector Passwords = new Vector();
private Vector MaxConns = new Vector();
private Hashtable ConnPools = new Hashtable();
public ConnManager() {
PoolNames.addElement("bbs");
DriverNames.addElement("org.gjt.mm.mysql.Driver");
DbIds.addElement("jdbc:mysql://localhost:3306/bbs");
UserNames.addElement("root");
Passwords.addElement("123");
MaxConns.addElement("10");
createPool();
}
private void createPool() {
for(int i = 0; i<PoolNames.size();i++){
String PoolName = PoolNames.elementAt(i).toString();
String DriverName = DriverNames.elementAt(i).toString();
String DbId = DbIds.elementAt(i).toString();
String UserName = UserNames.elementAt(i).toString();
String Password = Passwords.elementAt(i).toString();
int Maxconn=0;
try {
Maxconn = Integer.parseInt(MaxConns.elementAt(i).toString());
}
catch (NumberFormatException e) {
e.printStackTrace();
}
ConnPool Pool = new ConnPool(PoolName, DriverName, DbId,UseName, Password, Maxconn);
ConnPools.put(PoolName, Pool);
}
}
public Connection getConnection(String name) {
ConnPool Pool = (ConnPool) ConnPools.get(name);
if (Pool != null)
return Pool.getConnection();
return null;
}
public void releaseConnection(String name, Connection con) {
ConnPool pool = (ConnPool) ConnPools.get(name);
if (pool != null)
pool.releaseConnection(con);
}
public synchronized void destroyPool () {
Enumeration allPools = ConnPools.elements();
while (allPools.hasMoreElements()) {
ConnPool Pool = (ConnPool) allPools.nextElement();
Pool.destroyPool ();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -