???JAVA?е????????????????????
???????????? ???????[ 2013/8/30 9:51:14 ] ????????
??????????????????????????????????????????????????JDBC???????????????????URL???????????????Щ?????????????????????????????????嶨?????£?
public class ConnectionParam implements Serializable
{
private String driver; //?????????????
private String url; //?????????URL
private String user; //??????????
private String password; //?????????
private int minConnection = 0; //???????????
private int maxConnection = 50; //????????
private long timeoutValue = 600000;//????????????
private long waitTime = 30000; //??????????????п??????????????
????????????????????ConnectionFactory???????????????????????????????????????????????????????????????????????????????????£?
/**
* ?????????????????????????????????????????????????
* @author liusoft
*/
public class ConnectionFactory
{
//?ù??????????????????????????????????
static Hashtable connectionPools = null;
static{
connectionPools = new Hashtable(2??0.75F);
}
/**
* ???????????л?????????????????????
* @param dataSource ????????????????
* @return DataSource ????????????????????
* @throws NameNotFoundException ????????????????
*/
public static DataSource lookup(String dataSource)
throws NameNotFoundException
{
Object ds = null;
ds = connectionPools.get(dataSource);
if(ds == null || !(ds instanceof DataSource))
throw new NameNotFoundException(dataSource);
return (DataSource)ds;
}
/**
* ????????????????????????e?????????????????????
* @param name ?????????????
* @param param ?????????ò??????????????ConnectionParam
* @return DataSource ????????????????????
* @throws NameAlreadyBoundException ???????name??????????????
* @throws ClassNotFoundException ?????????????????е???????????
* @throws IllegalAccessException ??????????е???????????????
* @throws InstantiationException ??????????????????
* @throws SQLException ?????????????????????
*/
public static DataSource bind(String name?? ConnectionParam param)
throws NameAlreadyBoundException??ClassNotFoundException??
IllegalAccessException??InstantiationException??SQLException
{
DataSourceImpl source = null;
try{
lookup(name);
throw new NameAlreadyBoundException(name);
}catch(NameNotFoundException e){
source = new DataSourceImpl(param);
source.initConnection();
connectionPools.put(name?? source);
}
return source;
}
/**
* ???°???????????
* @param name ?????????????
* @param param ?????????ò??????????????ConnectionParam
* @return DataSource ????????????????????
* @throws NameAlreadyBoundException ???????name??????????????
* @throws ClassNotFoundException ?????????????????е???????????
* @throws IllegalAccessException ??????????е???????????????
* @throws InstantiationException ??????????????????
* @throws SQLException ?????????????????????
*/
public static DataSource rebind(String name?? ConnectionParam param)
throws NameAlreadyBoundException??ClassNotFoundException??
IllegalAccessException??InstantiationException??SQLException
{
try{
unbind(name);
}catch(Exception e){}
return bind(name?? param);
}
/**
* ???????????????????
* @param name
* @throws NameNotFoundException
*/
public static void unbind(String name) throws NameNotFoundException
{
DataSource dataSource = lookup(name);
if(dataSource instanceof DataSourceImpl){
DataSourceImpl dsi = (DataSourceImpl)dataSource;
try{
dsi.stop();
dsi.close();
}catch(Exception e){
}finally{
dsi = null;
}
}
connectionPools.remove(name);
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11