将 java 日期时间插入 Oracle

insert java date time into Oracle

服务器上的 Oracle 日期格式是 MM/DD/YYYY HH24:Mi:SS

我想在 Oracle 日期列中插入一个包含带有时间戳的日期的变量。

我在将日期插入 Oracle "date column ends before format picture ends" 时出错。

我想要的只是将特定时间戳附加到 java 字符串日期并将该 string/date 格式插入 Oracle 数据库

示例:

String incoming_date = request.getParameter("insert_date"); //this comes as a string in dd-mon-yyyy format

formatted_incoming_date = incoming_date + " 00:00:01"; //I want to append time factor to above variable with 00:00:01

insert into testtable values(formatted_incoming_date);

为什么要尝试将日期作为字符串插入?似乎在 Oracle 中存在从字符串到日期的隐式转换。可以用java.sql.Date代替吗?

无论如何,只要日期格式为 dd-mon-yyyy,您就必须将其转换为 java.sql.Date 对象,或者将其转换为适合 Oracle 字符串表示形式的 MM/DD/YYYY HH24:Mi:SS,即 Oracle "12/05/2016 00:00:00"

的传入日期 "05-12-2016" 字符串

试试这个

insert into testtable values(TO_DATE (formatted_incoming_date, 'dd-mon-yyyy hh24:mi:ss);