您的位置:首页 > 编程语言 > Java开发

java读取配置文件的几种方法

2007-03-23 21:40 1056 查看
今天因为要输出形如下面的语句:

recordVO.addElement("REPORT_ID", rs.getString("REPORT_ID"));
尝试写个小程序来实现该种形式的输出:

private String temp = "recordVO.addElement(\"%rowname%\", rs.%getmethod%(\"%rowname%\"));\n";

public void doAddElmtGene() throws Exception {
StringBuffer sbValue = new StringBuffer(512);
Connection conn = OracleTmplTblTest.getConnection();
DatabaseMetaData dbmd = conn.getMetaData();
ResultSet rs = dbmd.getColumns(null, dbmd.getUserName(), "CS_SS_ACCIDENT_DEVICE_REPORT", null);
while (rs.next()) {
sbValue.append(this.getOutputStr(rs.getString("COLUMN_NAME"), rs.getInt("DATA_TYPE")));
}
System.out.println(sbValue);
}

private String getOutputStr(String rowname, int type) {
Map values = new HashMap();
values.put("rowname", rowname);
String getmethod = "";
if (type == Types.DECIMAL || type == Types.VARCHAR) {
getmethod = "getString";
} else if (type == Types.DATE || type == Types.TIME | type == Types.TIMESTAMP) {
getmethod = "getDate";
} else if (type == Types.BLOB) {
getmethod = "getBlob";
}
values.put("getmethod", getmethod);
return this.getRenderStr(values);
}

private String getRenderStr(Map values) {
String value = temp;
Iterator it = values.keySet().iterator();
String key = null;
while (it.hasNext()) {
key = (String) it.next();
value = value.replaceAll("%" + key + "%", (String) values.get(key));
}
return value;
}

public static void main(String[] args) {
GeneRe g = new GeneRe();
try {
g.doAddElmtGene();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: