Reputation: 643
I need to take a date from user using JdateChooser then Increment in the days of that date by 2 then save the date in database.
I am using eclipse and this is the code I am trying;
DateFormat df=new SimpleDateFormat("dd-MM-yyyy");
String ADate=df.format(dateChooser.getDate());
Date date = df.parse(ADate); //Error comes here
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_MONTH, 2);
Date futureDate = cal.getTime();
String outD=df.format(futureDate); //And also here
System.out.println(outD);
I always get error:
java.util.date can not be cast to java.sql.date
Upvotes: 0
Views: 543
Reputation: 4076
It must be only a wrong import issue. Check that you are using
import java.util.Date;
and not
import java.sql.Date;
The parse()
method of DateFormat returns java.util.Date
.
Upvotes: 2