I want to update the string date into MySQL database using prepared statement. I have tried a lot and always got error java.util.Date cannot parse into java.sql.Date or vise versa. I didn't import anything here. Please import according to your answer.
public class Date1
{
public static void main(String args[])
{
String source="2008/4/5";
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
java.sql.Date d=(Date) format.parse(source);
Class.forName("com.mysql.jdbc.Driver");
Connection con=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/employee", "root", "root");
PreparedStatement ps=con.prepareStatement("insert into ankur1 values(?)");
ps.setDate(1,(java.sql.Date) d);
ps.executUpdate();
}
}