準備済みステートメントを使用して、文字列の日付を MySQL データベースに更新したいと考えています。私は多くのことを試しましたが、常にエラーが発生java.util.Date cannot parse into java.sql.Date
するか、その逆です。ここでは何もインポートしませんでした。回答に従ってインポートしてください。
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();
}
}