Home > Database > Mysql Tutorial > body text

向Oracle中插入date数据类型

WBOY
Release: 2016-06-07 17:12:01
Original
1591 people have browsed it

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

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!