2

我在 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;
}  

先感谢您。

4

0 回答 0