Java.sql.Date到Oracle数据库的日期和时间戳 [英] Java.sql.Date to Oracle database Date and Timestamp
问题描述
我正在使用Spring JDBC模板进行jdbc操作. 由于我使用的是BeanPropertySqlParameterSource,因此将bean的START_TIME变量分配为java.sql.date类型. 在Oracle数据库中,该列被称为"DATE"类型(并且没有TIMESTAMP类型,即使数据库为10.2 ver)
I am using Spring JDBC template for jdbc operations. Since I am using BeanPropertySqlParameterSource, the bean's START_TIME variables is assigned with java.sql.date type. in Oracle db, the column is mentioned as "DATE" type (and don't have TIMESTAMP type, even the db is 10.2 ver)
现在,当我设置
bean.setStartTime(new Date(System.currentTime())
它的存储日期和时间戳记为00:00:00
it's storing with date and time stamp as 00:00:00
请告诉我如何存储时间戳.
Please tell me how can i Store the time stamp also.
推荐答案
您需要使用java.sql.Timestamp
bean.setStartTime(new java.sql.Timestamp(...))
java.sql.Date
删除时间部分
要符合SQL DATE的定义,必须通过将特定时区中的小时,分钟,秒和毫秒设置为零来标准化" java.sql.Date实例包装的毫秒值.实例与之关联.
这篇关于Java.sql.Date到Oracle数据库的日期和时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!