File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Collision of Date format between java.sql and SQL  Server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Collision of Date format between java.sql and SQL  Server" Watch "Collision of Date format between java.sql and SQL  Server" New topic
Author

Collision of Date format between java.sql and SQL Server

rameshmca rk
Greenhorn

Joined: Jan 27, 2007
Posts: 17
Hi,
I have a doubt about setting date format for database field when I use java.sql.Date format in my java applications.There is a collision between SQL Server's "month/day/year' format and java.sql.Date class' "year/month/day" format.If I tried to store "year/month/day" format in SQL Server table I got the error "Microsoft ODBC SQLException, Optional feature not implemented". How can I store that kind of date in SQL Server? Can I create american date format in java?How?

Yours faithfully,
Ramesh RK
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2510
    
  10

This should not happen.

Can you please post your java code part, including insert/update statement, and the code where you set the date?

Regards, Jan


OCUP UML fundamental and ITIL foundation
youtube channel
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30913
    
158

See the code accidentally created as a new post.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30913
    
158

You are using
ps.setDate(5,dtF5);
which should be taking care of the date setting for you.

There isn't a different format for java.sql.Date in Java. It just represents a number of milliseconds. If you output the date value before setting it in the prepared statement, is it correct?
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2510
    
  10

I see (in the code thread) that your table column is defined as DateTime.

Try using setTimestamp() to set the value for the field.

This solved this person's similar problem.

Regards, Jan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Collision of Date format between java.sql and SQL Server