Forums Register Login

getting Date and Time

+Pie Number of slices to send: Send
Hi,
I have inserted the date and time to the table like this:
insert into x
values( to_date('11/26/2001:14:00:00', 'mm/dd/yyyy:hh24:mi:ss'));
Then I can retrieve it in SQL
select to_char(date1,'mm/dd/yyyy:hh24:mi:ss') as date1 from x;
but from Jdbc this sql is not working, the resultset is empty.
this is the part of the code:

it prints "Not null" and not next.
Could anyone throw some light on this?
Thanks,
Vanitha.


[This message has been edited by Vanitha Sugumaran (edited November 26, 2001).]
+Pie Number of slices to send: Send
I don't think the code is doing what you intended it to do.
1.
The line "if(rs != null){System.out.println("Not Null");}" accomplishes nothing . The only case in which rs would be null, would be if there was an exception thrown. In that case, the code would just jump to the exception handling block anyways. So just remove this line
2.
This line works fine: "if(!rs.next()){System.out.println("I'm not next");}". It checks to see if there are any results, and moves the cursor to the first row.
3.
This line is not doing what you think: "while(rs.next()){java.sql.Date date1 = rs.getDate("date1");}". In this line you are saying, if there are rows, then process the results...starting at row 2! You never process row 1 because by the time you get to processing your code you have called rs.next() twice, moving you to the second row in your resultset. If there is only one row (and this should be your case), You will get -->it prints "Not null" and not next.
Resolution: something like this:

Does this do what you wanted? If not, what were your intentions?
Jamie

[This message has been edited by Jamie Robertson (edited November 26, 2001).]
+Pie Number of slices to send: Send
Hi Jamie,
Thanks for your reply. I wasn't clear in my previous message sorry about that. I tried that sql query i didn't get any results so I tried th is null, or not next steps... just to check what's going on..
Ok, now coming to the problem, i tried as you suggested, since the we are retrieving date1 as char, when we getDate("date1"), I get illegal Argument exception.
If I getString("date1"), then it returns the exact stored date value.
Is there any other way to solve this problem? This is my intention, to get the date and time stored in database and compare them to system date. I didn't implement the comparison, just trying to retrieve the values.
Thanks,
Vanitha.
+Pie Number of slices to send: Send
Sorry, I didn't change the sql String. It's hard to retrieve a Date when a String is returned! ...I also used the wrong type of Date! Try this:

let me know how it goes
Jamie
[This message has been edited by Jamie Robertson (edited November 27, 2001).]
+Pie Number of slices to send: Send
Jamie,
Thanks for your reply. I will check your suggestion and let you know how it works. See, I have solution for my intention, checking whether the time stored in database is equal to system time.
select to_char(date1,'mm-dd-yyyy HH24:MI') from x
where to_char(date1, 'mm-dd-yyyy hh24:mi') = to_char(sysdate,'mm-dd-yyyy hh24:mi');

I am a newbie to Oracle.. so finally I got it. Thanks for your help. I will let you about your code later.
Vanitha.
Rototillers convert rich soil into dirt. Please note that this tiny ad is not a rototiller:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1579 times.
Similar Threads
oracle DATE
SQLException Cursor Closed
Performence issue:Write query directly in session bean or call storted procedure
required format
Date format
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 04:07:40.