可将java中的Date类型数据直接插入到Oracle数据库中Date类型的表字段
...
public UpdateSchedule addUpdateSchedule(Actor actor,String scheduleTitle,Integer updateType,
Integer terminalSoftwareId,Integer unitId,Integer cascadestatus,
Date beginDate,Integer schedulestatus,String memo,String updatetypes)
throws NoMethodAuthorityException,NoObjectAuthorityException,
ErrordataException,NoAvailableActorException {
Actor trueActor = appPool.getActor(actor);
UpdateSchedule updateSchedule
= new UpdateSchedule(scheduleTitle,updateType,terminalSoftwareId,
unitId,cascadestatus,beginDate,schedulestatus,memo);
try {
em.persist(updateSchedule);
em.flush();
}catch (Exception e) {
e.printStackTrace();
}
return updateSchedule;
}
(转)
1.利用Oracle中的方法to_date();
...
String DateStr = "1985-07-11 10:30:00.0 ";
pstmt = conn.prepareStatement( "INSERT INTO t(d) VALUES(to_date(?,'YYYY-MM-DD HH24:MI:SS ') ");
pstmt.setString(1,DateStr );
2.java.sql.Date 不同于java.util.Date,前者是子类。pstmt.setDate方法参数类型是sql.Date。因此需要转换
day = new SimpleDateFormat().parse(DateStr,"yyyy-MM-DD HH:mm:ss");
sql.Date sday = new Date(day.getTimes());//
pstmt.setDate(sday);
3.但是只保留了日期,而没有小时,如果想保存到24小时精确时间,用这种。
java.util.Date Dates = new java.util.Date();
java.sql.Timestamp time = new java.sql.Timestamp(Dates.getTime());
......
psmt.setTimestamp(3,time);
本篇文章来源于 Linux公社网站(www.linuxidc.com) 原文链接:http://www.linuxidc.com/Linux/2012-03/55729.htm
原文链接:https://www.f2er.com/oracle/211500.html