I have a variable of type Date. I get this date by using a function that return type Date. So, I defined two variables as:
Date expDate=null, startDate=null;
Then, I called the functions:
expDate=c.getNotAfter();
startDate= c.getNotBefore();
Then, inserted into the database using:
prepStmt.setDate(1,(java.sql.Date) startDate);
prepStmt.setDate(2, (java.sql.Date) expDate);
After running the program, I get this error:
java.util.Date cannot be cast to java.sql.Date
The columns in the database are defined as DATETIME type. How can I resolve the issue?