//初始化結果集
private void initResultSet(String dsList, Properties props) throws SQLException {
//獲取數據庫配置
final String url = props.getProperty("URL");
final String user = props.getProperty("USER");
final String passwd = props.getProperty("PASSWD");
if(url==null || user==null || passwd==null) {
return;
}
//判斷Oracle驅動是否存在
if(FooDb.getInstance().isFoundOracleDriver()==false) {
return;
}
Connection conn = FooDb.getInstance().getConnector(url, user, passwd);
Statement stat = FooDb.getInstance().getQueryStat(conn);
//分割所有數據源
final String[] dss = dsList.split(",");
//遍歷所有數據源
for(int i = 0; i < dss.length; ++i) {
String sql = props.getProperty(dss[i]);
ResultSet rs = FooDb.getInstance().execQuery(stat, sql);
int colsCount = FooDb.getInstance().getColsCount(rs);
//定義單數據源的記錄行
ArrayList<ArrayList<String>> rows = new ArrayList<ArrayList<String>>();
//表頭各列
/*
ArrayList<String> header = new ArrayList<String>();
for(int i = 1; i <= colsCount; ++i) {
header.add(FooDb.getInstance().getColName(rs, i));
}
rows.add(header);
*/
//遍歷各行
while(rs.next()) {
ArrayList<String> row = new ArrayList<String>();
for(int j = 1; j <= colsCount; ++j) {
row.add(rs.getString(j));
}
rows.add(row);
}
FooDb.getInstance().closeRs(rs);
//將單個結果集存入到結果集容器
this.mResuleSet.put(dss[i], rows);
}
//關閉語句對象和數據庫連接
FooDb.getInstance().closeStat(stat);
FooDb.getInstance().closeConn(conn);
} |