I want to insert a product into table. For that I have a Date field for which I use Date Chooser Combo. and for adding date for that product I wrote the following code,
String sql = "INSERT INTO ProductInfo(Name,Price,Date,Image,Category) values(?,?,?,?,?) ";
pst=conn.prepareStatement(sql);
pst.execute();
pst.setString(1, txt_name.getText());
pst.setString(2, txt_price.getText());
SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy");
String addDate = dateFormat.format(txt_AddDate.getDateFormat());
pst.setString(3, addDate);
But this is giving me "Cannot format given object as a date" error. I've tried a lot but can't solve. Anyone help me please?