返回数据格式
// 查询全部问题
public ArrayList queryQuestion() {
ArrayList paraList = new ArrayList();
try {
// 加载驱动程序
Class.forName(driver);
// 使用getConnection方法链接数据库
conn = DriverManager.getConnection(url, user, password);
// sql语句
String sql = "SELECT * FROM question ";
// 创建执行对象
Statement state = conn.createStatement();
ResultSet rs = state.executeQuery(sql);
while (rs.next()) {
String str = rs.getString("content_img");
String[] line = str.split(",");
// imgArr.add(str);
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", rs.getInt("id"));
map.put("title", rs.getString("title"));
map.put("quesion_id", rs.getInt("quesion_id"));
map.put("content", rs.getString("content"));
// map.put("content_img", rs.getString("content_img"));
map.put("content_img", line);
map.put("answer_num", rs.getInt("answer_num"));
map.put("like_num", rs.getInt("like_num"));
paraList.add(map);
}
rs.close();
conn.close();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return paraList;
}