In the below line...
(Date)formatter.parse(str)
You are trying cast java.util.Date
type Date
object to java.sql.Date
type Date
object...that's why its throwing this Exception
java.lang.ClassCastException: java.util.Date cannot be cast to java.sql.Date
And its causing due to import of the below package...
import java.sql.Date;
You should import the package as below...So, you should remove the above import and import this below one.
import java.util.Date;