Home  >  Article  >  Database  >  向Oracle中插入date数据类型

向Oracle中插入date数据类型

WBOY
WBOYOriginal
2016-06-07 17:12:011629browse

1.利用Oracle中的方法to_date(); String DateStr = 1985-07-11 10:30:00.0 ; pstmt = conn.prepareStatement( I

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);

但是只保留了日期,而没有小时,如果想保存到24小时精确时间,,用下一种。

3.

   java.util.Date Dates = new java.util.Date();
        java.sql.Timestamp time = new java.sql.Timestamp(Dates.getTime());
        ......
       psmt.setTimestamp(3, time);

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn