0

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

James Z
  • 12,209
  • 10
  • 24
  • 44
Maha Waqar
  • 585
  • 1
  • 10
  • 24

1 Answers1

2

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.

Rajeev Ranjan
  • 3,588
  • 6
  • 28
  • 52