• 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

Dates help

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
i have a date in the format "24/12/2004 19:10:11". This date has to be put into the database. the java.sql.date seems to be taking only the part "24/12/2004" and not he time part.

Plz help
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
store the milliseconds into the db (don*t use Date but Long e.g.) and
when you retrieve your objects create new DateObjects based on the milliseconds.
Maybe this solves your prob
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Is the field in the database table declared as a "datetime" or just "date"?
2. Can you show the code you are using to construct the java.sql.Date object?
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you want to use a "java.sql.Timestamp" instance, which will preserve both the date and time portion. Most databases will ignore the time portion of a "java.sql.Date" instance.
 
Sarah Gaikwad
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a stored procedure that inserts values into the table. A callable statement is used to put these values into the table.
payment_dt datetime.//in the db
//in java
java.sql.Date p_dt
cstmt.setDate(10,p_dt);
setDate always takes the 2nd parameter as an objectof type java.sql.Date.
Can u plz tell me if java.sql.Timestamp will help and how i can use it
Thanks
Sharun
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sharun,


java.sql.Timestamp ... how i can use it


You can use the "setTimestamp()" method in the CallableStatement interface. However, I get the impression that you are just hoping that this will solve your problem. Perhaps if you gave some more details about your problem, you may get a better answer. I suggest starting with the following details:
  • DBMS you are using
  • stored procedure code
  • java code used to invoke the stored procedure
  • complete error message and stack trace you are getting (if any)


  • Good Luck,
    Avi.
     
    Sarah Gaikwad
    Ranch Hand
    Posts: 35
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I managed to create a Timestamp object, the code of which is below.
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss ");
    Calendar calendar =Calendar.getInstance();
    calendar.set(Integer.parseInt((cpdt.substring(cpdt.lastIndexOf("/")+1,cpdt.indexOf(":")-2)).trim()),Integer.parseInt(cpdt.substring(cpdt.indexOf("/")+1,cpdt.lastIndexOf("/")))-1,Integer.parseInt(cpdt.substring(0,cpdt.indexOf("/"))));
    calendar.set(Calendar.HOUR ,Integer.parseInt(cpdt.substring(cpdt.indexOf(":")-2,cpdt.indexOf(":")).trim()));
    calendar.set(Calendar.MINUTE,Integer.parseInt(cpdt.substring(cpdt.lastIndexOf(":")-2,cpdt.lastIndexOf(":"))));
    calendar.set(Calendar.SECOND,Integer.parseInt(cpdt.substring(cpdt.lastIndexOf(":")+1)));
    calendar.set(Calendar.AM_PM,1);
    class_variable_pdt = Timestamp.valueOf(sdf.format(calendar.getTime()));

    I am able to add the same to the db. The problem i am now facing is that if i store the date as 05/05/2002 19:33:50 ,it stores the same as 2004-05-05 7:33:50 am,this is incorrect.
    if i set the simpledateformat object to "yyyy-MM-dd hh:mm:ss a", the timestamp gives an error.
    plz help
     
    Why should I lose weight? They make bigger overalls. And they sure don't make overalls for tiny ads:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic