public class DBConn {
public static String erro;
private static Context initCtx = null;
private static ComboPooledDataSource ds = null;
//private static ComboPooledDataSource dataSource;
static String strDriver;
static String strDb;
static String strUser;
static String strPsw;
static int count;
static int MIN_COUNT=5;
static int MAX_COUNT=25;
static String strDataName;
static String strHostAddress;
static int intHostPort;
static LinkedList queue;
public DBConn(String filePath){
try {
FileInputStream propsFile = new FileInputStream(filePath);
Properties properties = new Properties();
properties.load(propsFile);
propsFile.close();
strDriver = properties.getProperty("connDriver");
strDb = properties.getProperty("connDBParam");
strUser = properties.getProperty("connUser");
strPsw = properties.getProperty("connPwd");
MIN_COUNT = Integer.parseInt(properties.getProperty("minCount"));
MAX_COUNT = Integer.parseInt(properties.getProperty("maxCount"));
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String args[]){
Connection con = null;
try{
DBConn dbConn = new DBConn("./inf/dbConn.txt");
con = dbConn.getConnection();
System.out.println("message:"+con);
}catch (Exception e){
e.printStackTrace();
}finally {
if(con != null)
try{restoreConn(con);}catch(Exception e){}
}
}
}
dbConn.txt
connDriver=com.microsoft.sqlserver.jdbc.SQLServerDriver
connDBParam=jdbc:sqlserver://127.0.0.1:1433;selectMethod=cursor;DatabaseName=資料庫名
connUser=sa
connPwd=sa
count=10
minCount=5
maxCount=20
check=10