I get data from oracle with result set and then populate them to cachedrowset
. But when I get a date field in database and print it, it only print the date. I check the api and know that the getDate()
method return java.sql.date
,and time of sql.date
is casted to 0. I test that if I call resultset.getString("datefield")
, it can get whole date and time data, so is there any way to get whole date and time data using cahcedrowset
, thanks
here's my source code
CachedRowSet rs = null;
try {
rs = executeQuery("select * from t_web_order_result ");
if (rs != null && rs.next()) {
KKLog.info(rs.getDate("stime"));//2012-04-24,it should be 2012-04-24 09:23:33
KKLog.info(rs.getString("stime"));
}
} catch (SQLException e) {
logErr("queryCheckers Err", e);
} finally {
closeCachedRowset(rs);
}
executeQuery method
CachedRowSet rowset = null;
Connection connection = null;
PreparedStatement statement = null;
ResultSet rs = null;
try {
connection = getConnection();
statement = connection.prepareStatement(sql);
for (int i = 0; i < params.length; i ++) {
statement.setObject(i + 1, params[i]);
}
rs = statement.executeQuery();
rowset = new CachedRowSetImpl();
rowset.populate(rs);
rs.close();
statement.close();
} finally {
//close....
}
return rowset;
i used three method to print the log
KKLog.info(rs.getDate("stime"));
KKLog.info(rs.getString("stime"));
KKLog.info(rs.getTimestamp("stime"));
and the log content is
12-11-11 17:06:11 2012-04-24
12-11-11 17:06:11 2012-04-24
12-11-11 17:06:11 2012-04-24 00:00:00.0