/**
* 谁能告诉我这个方法怎么测试?
* **/
public List<Map> doExeuteQuery(String sql, Object[] o) {
boolean flg = false;
PreparedStatement pre = null;
ResultSet rs = null;
Statement stmt = null;
ResultSetMetaData metaData = null;
List<Map> list = new ArrayList<Map>();
con = this.getConnection();
try {
pre = con.prepareStatement(sql);
if (o.length > 0) {
for (int i = 1; i <= o.length; i++) {
pre.setObject(i, o[i - 1]);
}
}
rs = pre.executeQuery();
int count = 0;
metaData = rs.getMetaData();
int colum = metaData.getColumnCount();
while (rs.next()) {
count++;
Map map = new HashMap();
for (int i = 1; i <= colum; i++) {
map.put(metaData.getColumnName(i).toUpperCase(), rs
.getObject(metaData.getColumnName(i)) == null ? ""
: rs.getObject(metaData.getColumnName(i)));
}
list.add(map);
}
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException();
} finally {
this.close(rs, pre, con);
}
return list;
}
* 谁能告诉我这个方法怎么测试?
* **/
public List<Map> doExeuteQuery(String sql, Object[] o) {
boolean flg = false;
PreparedStatement pre = null;
ResultSet rs = null;
Statement stmt = null;
ResultSetMetaData metaData = null;
List<Map> list = new ArrayList<Map>();
con = this.getConnection();
try {
pre = con.prepareStatement(sql);
if (o.length > 0) {
for (int i = 1; i <= o.length; i++) {
pre.setObject(i, o[i - 1]);
}
}
rs = pre.executeQuery();
int count = 0;
metaData = rs.getMetaData();
int colum = metaData.getColumnCount();
while (rs.next()) {
count++;
Map map = new HashMap();
for (int i = 1; i <= colum; i++) {
map.put(metaData.getColumnName(i).toUpperCase(), rs
.getObject(metaData.getColumnName(i)) == null ? ""
: rs.getObject(metaData.getColumnName(i)));
}
list.add(map);
}
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException();
} finally {
this.close(rs, pre, con);
}
return list;
}