I have a GUI java interface that allows me to open a JDataPicker in order to insert the selected date into a ms-access database.
I tried inserting the date directly from the JDataPicker : Date date1 =(Date) jdate_picker.getModel().getSelectedValue(); However, the format retrieved returns : java.text.ParseException: Unparseable date: “Tue Apr 26 00:00:00 EDT 2016” (at offset 0).
I attempted several things but nothing seems to work. For instance, I tried retrieving the month, year and day separately through jdate_picker.getModel().getYear () (and getMonth() and getDay()). Then I concatenated the results to get a MM/DD/YYYY format. After that I used DateFormatter to convert the string to a date format but it still, I'm getting date format exceptions. My questions are as follow:
1- Is there a way that I haven't thought of which would allow me to insert a date from JDatePicker into an Access database?
2- If not, is there another tool that would allow me to select a date and send it to the Access database?
Thank you.
You are using troublesome old date-time classes that have been supplanted by the java.time classes. Avoid using
Date
andCalendar
.For a date-only value without time zone and without time-of-day, use
LocalDate
.Exchange data with your database as objects rather than mere strings.
If your JDBC driver complies with JDBC 4.2 and later, you can directly use java.time objects.
And to retrieve:
These issues have been covered many times already on Stack Overflow. Search for more info.