Possible Duplicate:
How to convert java.util.date to java.sql.date?
I found error on my function, it shows error result after initializing the newInstance() method from DatatypeFactory df , I'm getting another error:
java.lang.ClassCastException: java.util.Date cannot be cast to java.sql.Date
I just change the package name from
java.util.Date into java.SQL.Date
then casting:
Date dateStarting = (Date) jDateChooserStart.getDate();
Date dateEnding = (Date) jDateChooserEnd.getDate();
How to resolve this issue?
(post before: Convert jcalendar Date into XMLGregorianCalendar Getting Null Value)
If we have the Date object of the SQL package, then we can easily convert it into an util Date object. We need to pass the getTime() method while creating the util Date object. java.
sql. Date just represent DATE without time information while java. util. Date represents both Date and Time information.
It's not possible to cast from java.util.Date
to java.sql.Date
. You need to convert from one type to the other instead:
java.util.Date utilStartDate = jDateChooserStart.getDate();
java.sql.Date sqlStartDate = new java.sql.Date(utilStartDate.getTime());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With