返回数据格式
// 查询全部问题
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;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。