• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getting Date and Time

 
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Vanitha Sugumaran
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Vanitha Sugumaran
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Would you turn that thing down? I'm controlling a mind here! Look ... look at the tiny ad ...
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic