加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

向Oracle中插入date数据类型

发布时间:2020-12-12 15:38:21 所属栏目:百科 来源:网络整理
导读:可将java中的Date类型数据直接插入到Oracle数据库中Date类型的表字段 ... public UpdateSchedule addUpdateSchedule(Actor actor,String scheduleTitle,Integer updateType, Integer terminalSoftwareId,Integer unitId,Integer cascadestatus, Date beginDa

可将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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读