我在java中编写了一个方法,它从MySQL数据库中检索数据并添加到列表中。但是,尽管数据库中存在数据,但该方法为少数ID返回空值。
以下是代码:
public static List getPostTime(int ID) {
List<Timestamp> time = new ArrayList();
try {
PreparedStatement ps;
ResultSet rs;
Connection con;
con = DBConnection.getDBConnection();
String queryTime = "select created from tbl_posts_98 where `MakerID` = \'" + ID + "\'";
ps = con.prepareStatement(queryTime);
rs = ps.executeQuery();
while (rs.next()) {
time.add(rs.getTimestamp(1));
}
} catch (java.lang.Throwable t) {
//System.out.println(t.getClass().getName()); //this'll tell you what class has been thrown
t.printStackTrace(); //get a stack trace
}
return time;
}
提前谢谢。