我有一個方法,它通過日期對象返回ResultSet查詢的值。這個障礙是,在我的輸出中,它只返回特定列中的最後一個值。我如何去做這件事?ResultSet不迭代指定列的值
public Date getTime(){
Date date = null;
DateFormat format;
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url, "root", "");
Statement stmt = con.createStatement();
ResultSet result = stmt.executeQuery("SELECT * FROM error_log WHERE service_source = 'Billbox' ");
while (result.next()) { //retrieve data
String ds = result.getString("error_date");
format = new SimpleDateFormat("M/d/yyyy H:m:s a");
date = (Date)format.parse(ds);
}
con.close();
} catch (Exception ex) {
Logger.getLogger(LogDB.class.getName()).log(
Level.SEVERE, null, ex);
}
return date;
}
然後在我的主要方法:
public static void main(String args[]){
TestA ea = new TestA();
Date ss = ea.getTime();
System.out.println(ss);
}
但這僅返回我的查詢中的最後一個值。我怎麼能打印出其他(老年人)一起呢?
你好,如果上述任何一個答案解決了你的問題,請接受一個! – Simon
是選擇一個,然後點擊左上角的鉤子。 –