File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes smalldatetime format error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "smalldatetime format error" Watch "smalldatetime format error" New topic

smalldatetime format error

Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
Probably quite a simple problem but...

I have a simple form where a user inputs some data (including a date), I want the user to eneter the date in dd/mm/yyyy format (e.g. 21/02/2005), my SQL database is using 'smalldatetime' format, which as i see stores the date in dd/mm/yyy format. So, there shouldn;t be a problem should there? So why is it, when I insert a new record i get a:

"java.sql.SQLException: The conversion of char data type to smalldatetime data type resulted in an out-of-range smalldatetime value." error? Is it because I don;t have any time values on the end of the date (e.g. 21/02/2005 00:00:00.00 or summin')?


myriah wind

Joined: Mar 04, 2005
Posts: 14
post the code
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

I strongly recommend using a prepared statement here. You can parse the date in Java and then pass the date object into a stored procedure. This allows the driver to deal with conversion details.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1141

Does "mySQL" support SQL Escape Syntax?

Good Luck,
Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
It's OK I changed it from smalldatetime to just datatime, that seems to have fixed it for some reason.
I agree. Here's the link:
subject: smalldatetime format error
jQuery in Action, 3rd edition