更新数据需要commit
在查询数据的时候,没有报错i,但就是无法显示打印,最后发现rs.get()与数据库中的字段不对应的原因
public List getMessage(String startRow,String num){
String sql ="select* from message limit "+startRow+","+num;
Connection conn = this.session.connection();
List list1 = new ArrayList();
try {
PreparedStatement pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while(rs.next()){
Message message = new Message();
message.setId(rs.getInt("id"));
message.setName("华讯财经股客");
message.setContent(rs.getString("content"));
System.out.println(rs.getString("content"));
String ip = rs.getString("ip").substring(0, 8).concat("*");
message.setIp(ip);
message.setPoint(rs.getInt("point"));
list1.add(message);
}
pstmt.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.getStackTrace();
}
return list1;
}