This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / 如何在oracle中插入datetime?我想在java中得到当前时间(精确到秒), 然后把它插入到oracle中的date中去, 我的代码如下
Calendar calender = Calendar.getInstance();
java.sql.Timestamp ts = new java.sql.Timestamp(calendar.getTime());
......
PreparedStatement prep = conn.prepareStatement
("INSET INTO orders VALUS ?");
prep.setTimeStamp(1, ts);
prep.executeUpdate();
结果在数据库里面得到的值没有小时,分钟,秒。
那位大侠看看错在那里,谢谢!
...
-oasis(oasis);
2003-4-1
{447}
(#1117022@0)
-
你用什么命令看没有?
-yuanzidan(原子弹);
2003-4-1
(#1117212@0)
-
抓娃咱不会,甲骨文学过一点...Oracle 的Date肯定包括时间的,只不过,你默认的格式可能不显示时间。下面是在俺机器上跑出来的结果。
默认格式的结果:
SQL> SELECT SYSDATE "NOW" FROM DUAL;
NOW
---------
01-APR-03
格式化后的结果:
SQL> SELECT TO_CHAR(SYSDATE, 'MM-DD-YYYY HH24:MI:SS')"NOW" FROM DUAL;
NOW
-------------------
04-01-2003 15:03:38
-yehongwei(天拖南);
2003-4-1
{330}
(#1117326@0)
-
Try use select TO_CHAR(dateCol,'mm/dd/yyyy HH:MI:SS') from orders; Where dateCol is the column name. Could not see any problem with your java code (except several typo errors)but I would rather use PreparedStatement prep = conn.prepareStatement
("INSERT INTO ORDERS VALUES (sysda
te)"); Consider mutiple servers (JVMs), in this way you can have a unique time interface... hope it helps.
-xiaoxiao(笑笑);
2003-4-1
{216}
(#1117640@0)
-
谢谢楼上各位,实际上时间已经在里面,只是现实的不对,用TO_CHAR就好了
-oasis(oasis);
2003-4-1
(#1117745@0)