且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从oracle插入并提取每小时一小时

更新时间:2023-12-05 22:40:52

你是对的。我不太了解Oracle的Java接口知道正确的解决方案。但是,您的解决方案是立即插入日期。表达式:

  to_char(transfers.DATE_ARCH,'HH:MM')

返回12,因为那是午夜和05,因为它是五月。分钟的正确表达式为:

  to_char(transfers.DATE_ARCH,'HH:MI')

和24小时制:

  to_char(transfers.DATE_ARCH,'HH24:MI')

我没有,唉,知道如何修复java代码。但也许你可以使用 DateTime 方法。


I work with oracle

I want to insert data which contains hour and minute

I have this column : DATE_ARCH

the type of this column is date

I have this java code which should insert date in this column

 transfers.setDateArch(new java.sql.Date(
                        System.currentTimeMillis()));

but when I try to extract hour and minute from DATE_ARCH

using this sql code :

select to_char(transfers.DATE_ARCH , 'HH:MM') from transfers where id_transfer='TR-300'

I have all time this value :

12:05

Updated :

I try with this code :

Timestamp t = new Timestamp(new Date().getTime());

                transfers.setDateArch(t);

I try to extract hour and minute using this code :

select to_char(transfers.DATE_ARCH , 'HH24:MI') from transfers where id_transfer='TR-258'

but I have in all case this value :

00:00

as I already said the type of DATE_ARCH is date

When I try in sql with :

  UPDATE transfers SET DATE_ARCH = SYSDATE

I have the correct value using

 select to_char(transfers.DATE_ARCH , 'HH24:MI') from transfers where id_transfer='TR-258'

now I want to know how can I insert date with hour and minute using java code

You are correct. I do not know enough about the java interface to Oracle to know the right solution. But, your solution is inserting the date with no time. The expression:

to_char(transfers.DATE_ARCH , 'HH:MM')

is returning "12" because that is midnight and "05" because it is May. The correct expression for minutes is:

to_char(transfers.DATE_ARCH , 'HH:MI')

and for a 24-hour clock:

to_char(transfers.DATE_ARCH , 'HH24:MI')

I do not, alas, know how to fix the java code. But perhaps there is a DateTime method that you can use.