I have a table column of data type DATE. I am inserting through Java PreparedStatement , how can I store timestamp also when inserting? Is it possible to store time stamp in DATE column?
I tried
ps.setTimestamp(index, new java.sql.Timestamp(date.getTime()));
But did not work.
Thanks in advance.
The mapping between SQL types and JDBC types in Oracle is a bit complicated, especially for the
DATEandTIMESTAMPSQL types.The Oracle database allows you to store timestamp information in DATE columns, which is quite contrary to the definition of the DATE in the SQL standard. Prior to 9.2 when the TIMESTAMP column support was introduced,
Statement.setTimestampwould work for DATE columns. Since 9.2, and until 11.1, the JDBC driver mapped the SQLDATEtype to the JDBCDateand the SQLTIMESTAMPtype to the JDBCTimestamp. The possible solutions to storing timestamps using the 10.2 JDBC drivers are listed in the Oracle JDBC FAQ, and are reproduced here:You could also use the JDBC 11.1 drivers (they will work against a 10g instance), and the FAQ has this to state: