我想将 JForm 中的值插入 mysql 数据库。但我无法将值插入日期字段。此代码在日期字段之外有效。有人能帮我吗..
String s1=txtUsername.getText();
String s2=txtPassword.getText();
String s3=txtName.getText();
String s4=txtAddress.getText();
String s5=txtContractEndDetails.getText();
connection getcon = new connection();
Connection conn;
try{
conn=getcon.creatConnection();
String sql="insert into TravelGuide(username,password,name,address,contract_end_date)values(?,?,?,?,?)";
PreparedStatement stmt = conn.prepareStatement(sql);
java.sql.Date dtValue = java.sql.Date.valueOf(s5);
stmt.setString(1, s1);
stmt.setString(2, s2);
stmt.setString(3, s3);
stmt.setString(4, s4);
stmt.setDate(5, s5);
stmt.executeUpdate();
}
catch(Exception ex){
JOptionPane.showMessageDialog(PanelTG, ex.getMessage(),"Error Occured 123",2);
}