public static List<Map<String, Object>>getResultToList(String sql, Object[]params) {
PreparedStatement ps = null;
Connection conn = getConnection();
ResultSet rs = null;
List<Map<String, Object>>rows = new ArrayList<Map<String, Object>>();
if (null == sql|| "".equals(sql)) {
return new ArrayList<Map<String, Object>>();
}
try {
ps =conn.prepareStatement(sql);
if (null !=params && params.length > 0) {
for (int i = 0,len = params.length; i < len; i++) {
Object arg =params[i];
ps.setObject(i+ 1, arg);
}
}
rs = ps.executeQuery();
if (null != rs){
ResultSetMetaDatarsm = rs.getMetaData();
int count= rsm.getColumnCount();
Map<String, Object>record = null;
if (count> 0) {
while(rs.next()) {
record= new HashMap<String, Object>();
for (int j = 0;j < count; j++) {
Object obj =rs.getObject(j + 1);
StringcolumnName = rsm.getColumnName(j + 1);
record.put(columnName.toLowerCase(),(obj== null) ? "" : obj);
}
rows.add(record);
}
}
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
release(rs, ps,conn);
}
return rows;
}