I have a working application that can write/update information to MS access.
I use Dates in my program, to show a booking sheets date. I use these as Strings right now, but I was wondering, if you could help me that is, what date should I set as one of my MS Access database fields, e.g: General Date 19/06/1994 17:34:23 Long Date 19 June 1994 Medium Date 19-Jun-94 Short Date 19/06/1994 Also, I want to be able to make my String representation of a date, get turned to a date obeject, used in the database, then turned back to the String again. can this be done? My format is a SimpleDateFormat Tuesday 08 May 2007.
I use these as Strings right now, but I was wondering, if you could help me that is, what date should I set as one of my MS Access database fields
If the data is a date, then a date/time data type is a much more appropriate data type to use. It makes sense to have a field that only allows dates, rather than any abitrary text (otherwise inserting 'ABC' is just as valid as insering 12/12/01 00:00:00).
I think dates in Access are really stored as a kind of wierd floating point number; left of the decimal point represents the date, right represents the time. When you see a format (such as General Date 19/06/1994 17:34:23) it's just that, a format, not the data itself. All Access is doing is applying a mask to the data to render it in a particular way it doesn't change how the date/time is stored.
Also, I want to be able to make my String representation of a date, get turned to a date obeject, used in the database, then turned back to the String again. can this be done?
Yes. You need to use a PreparedStatement and the setDate() method. This is a much better way of handling dates, since it removes all of the formatting issues from your code and delegates these to the driver.
I made my Access column_1 a long date, made it primary key.
I get an exception saying - "java.lang.ClassCastException: java.util.Date cannot be cast to java.sql.Date" here is the full stackTrace:
I checked the API, but I cant see what to do. How can I fix this so that I can store a Date from the String? I mainly want to change the string, cause I have taken 3 months on this, and dont want to go all over it and change the code for all the Strings to be dates.
I have a date as a String working in my program, but I want to change that String, in a different class, to an sql date so that I can store data to the database using this date.
this is my code so far which seems to go through the insert block all the time.
my database worked with column_1 set as varchar and I could store the date as a string, but i changed the database to a long date, which outputs on the database as 12 May 2007. I am converting my String to an sql date which outputs as 2007-05-12.
could you help me out with this problem, so that I can store an sql date in MS Access so that my database can work?