开发者

retrieve oracle database Date column in java using Calendar Instance and compare with today's date

I have Oracle database with Date column in it and I want to retrieve it from recordset using Calendar since I want to compare 开发者_Go百科it with today's date which is built using Calendar.


Not really sure what you meant with retrieving the date "using Calendar", but if you are using Java, and want to read a date from database and compare it with today's date, it goes like this:

java.sql.Date dbDate = resultset.getDate("dateField");
java.util.Date date = new Date(dbDate.getTime());
Calendar calendar = Calendar.getInstance();
java.util.Date today = calendar.getTime(); // "today = new Date();" would work just as well
if (date.before(today)) {
    // do something
} else if (date.after(today)) {
    // do something else
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜