File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date

 
satishind Reddy
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a table in Microsoft SQL data base. In that table one field is a Date field. I am getting error while inserting record. I am giving code snippet please help me. what am I doing wrong here.

Thanks in advance.
Regards
Satish


[This message has been edited by Thomas Paul (edited December 07, 2000).]
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Parsing the date in this way will simply remove the portions of the date that are not year-month-day but will not effect what is passed to the datatbase which is: 'Thu Dec 07 00:00:00 EST 2000'.
You need to use the SimpleDateFormat to convert the Date object into a String. Try this:
SimpleDateFormat fmt = new SimpleDateFormat ("MM/dd/yyyy");
String todate = fmt.format(date);

 
satishind Reddy
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Thomas,
Thanks for reply. Still it is giving problem because in table level my date field data type is 'datetime'.
SimpleDateFormat fmt = new SimpleDateFormat ("MM/dd/yyyy");
String todate = fmt.format(date);
here 'todate' is string. and table level field data type is 'datetime'. so it is giving data mismatch error.
please help to me. If i am not clear i can send code if u provide mail id.
Thanks
Satish
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All you have to do is figure out what is a valid String format that MS SQL will accept in a date/time field and then use SimpleDateFormat to reproduce that format.
 
maha anna
Ranch Hand
Posts: 1467
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Reddy,
The following is the code snippet which I use in My-SQL and Access. It may not be same in MS-SQL. You can try it. Otherwise please look into the documentation. In the foll. code the DOB(DateOfBirth) String has to be in yyyymmdd format
regds
maha anna

[This message has been edited by Thomas Paul (edited December 08, 2000).]
 
satishind Reddy
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi paul,
Paul i havn't noticed that 'MM' should be Caps otherwise it is taking minutes insted of month. Due to this i got error every time.
Thanks for all your replies.
Satish
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That will make a difference. Glad that your problem is solved!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic