私は次のクエリを持っている:JDBCプリペアドステートメント。 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/ –