I'm not so familiar with manipulating ArrayList<HashMap<String, String>>
. In this problem I want to save the return ArrayList<HashMap<String, String>>
from a function. However, I don't know weather if I code it wrong. Can anyone help me?
I've check my sql code, it work pretty fine and return the things that I want.
List<HashMap<String, String>> ErrorList= new ArrayList<HashMap<String, String>>();
ErrorList = select("SELECT * FROM process_result WHERE (status = 'Error') AND (mailBefore = 'No');");
public List<HashMap<String, String>> select(String query) {
List<HashMap<String, String>> output = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = null;
Statement statement = null;
try {
statement = this.conn.createStatement();
ResultSet rs = statement.executeQuery(StringEscapeUtils.unescapeJava(query));
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
map = new HashMap<String, String>();
while (rs.next()) {
for (int i = 1; i <= columnCount; i++ ) {
map.put(rsmd.getColumnName(i), rs.getString(i));
}
output.add(map);
}
} catch (SQLException e) {
logger.error(e);
e.printStackTrace();
}
//System.out.print("This is select output:" + output);
return output;
}
The code don't correctly save the return value from select function.