?? datasourcecreater.java
字號(hào):
package cn.netjava.feeserver.servletcontainer;
import javax.sql.DataSource;
import java.sql.*;
import cn.netjava.feeserver.cfgbean.CfgDataSource;
import org.apache.commons.dbcp.BasicDataSource;
import cn.netjava.feeserver.cfgbean.*;
/**
* 創(chuàng)建數(shù)據(jù)源,提供提取數(shù)據(jù)源接口
* 計(jì)費(fèi)查詢服務(wù)器
* @author www.NetJava.cn
*
*/
public class DataSourceCreater {
/**
* 提取對(duì)應(yīng)名字的數(shù)據(jù)源
* @param dataSourceName
* @return
* @throws Exception
*/
public static java.sql.Connection getDataSource(String dataSourceName) throws Exception{
DataSource ds=dataSourceMap.get(dataSourceName);
if(null==ds){
CfgDataSource cds=WebAppCfgManager.ins().getWebApp().getCfgDataSource(dataSourceName);
BasicDataSource bds=new BasicDataSource();
// bds.setLoginTimeout(1000);
bds.setDriverClassName(cds.getDriverClassName());
bds.setUrl(cds.getUrl());
bds.setMaxActive(cds.getMaxActive());
bds.setMaxIdle(cds.getMaxIdle());
bds.setUsername(cds.getUserName());
bds.setPassword(cds.getPassWord());
dataSourceMap.put(dataSourceName, bds);
return bds.getConnection();
}
return ds.getConnection();
}
// dataSource配置集合
private static java.util.Map<String,DataSource> dataSourceMap=new java.util.HashMap();
/**
* 連結(jié)數(shù)據(jù)庫(kù)
* @param driveName
* @param dbURL
* @param useerName
* @param pwd
* @return
*/
// public Connection getDataSource(String driveName,String dbURL,String useerName,String pwd) throws Exception{
// try{
//
// //到classpath中查找驅(qū)動(dòng)類:
// Class.forName(driveName);
// conn=java.sql.DriverManager.getConnection(dbURL, useerName, pwd);
// return conn;
// }catch(Exception ef){
// LogManager.error("conn to db error: "+ef);
// }
// return null;
// }
//
// private static Connection conn=null;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -