我有以下查询:JDBC Prepared Statement。 setDate(....)不会节省时间,只是日期..我怎样才能节省时间?
INSERT INTO users (user_id, date_created) VALUES (?,?)
我有以下几个准备好的声明
PreparedStatement insertUser = dbConnection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
insertUser.setInt(1, 7);
java.util.Date now = new java.util.Date(System.currentTimeMillis());
insertUser.setDate(2, new java.sql.Date((new Date(System.currentTimeMillis())).getTime()));
insertUser.executeUpdate();
如果我检查数据库,我发现它虽然只插入今天的日期,而不是时间,所以它将是:2011-07-29 00:00:00
我应该怎么把setDate()
也拿到时间呢?
http://www.mkyong.com/jdbc/how-to-insert-timestamp-value-in-preparedstatement/ –