我在jcalendar上有一个错误,它保存了1970-1-1的日期我从jdatechooser文本字段中选择了一个日期,但它却节省了一年。我怎么能解决这个问题,非常奇怪的错误我没见过类似的东西爱好。
更新按钮代码
private void updatebtnMouseClicked(java.awt.event.MouseEvent evt) {
//Date date=NextServiceDate1.getDate();
//String serviceDate=String.format("%1$tY-%1$tm-%1$td", date);
String currDate=null;
String cost=null;
String serviceDate=null;
try{
String name=txtname.getText();
String surname=txtsurname.getText();
String street=txtstreet.getText();
String city=txtcity.getText();
String mobile=txtmobile.getText();
String phone=txtphone.getText();
conn=con.getConn();
String Getsql="SELECT * FROM customers WHERE id="+lblID.getText();
pst=conn.prepareStatement(Getsql);
rs=pst.executeQuery();
while(rs.next()){
currDate=rs.getString("next_service");
cost=rs.getString("cost");
}
if("".equals(currDate)){ //CHECK IF THE DATE IN DATABASE IS EMPTY
serviceDate=null; //IF TRUE THEN ASSIGN TO CURRENT DATE EMPTY VALUE
}else if(NextServiceDate.getDate()!=null){ //ELSE
//String date=((JTextField)NextServiceDate.getDateEditor().getUiComponent()).getText(); //GET THE VALUE FROM JDATECHOOSER FORMAT DATE TO STRING
Date datef=NextServiceDate.getDate();
// SimpleDateFormat formatter=new SimpleDateFormat("YYYY-MM-DD");
serviceDate=String.format("%1$tY-%1$tm-%1$td",datef);
JOptionPane.showConfirmDialog(rootPane, serviceDate);
}
if(cost==null) { //IF COST FIELD IN DATABASE IS EMPTY
cost=null; //THEN ASSIGN TO COST NULL VALUE
}else if(txtcost.getText()!=null){ //ELSE IF COST TEXTFIELD IN NOT NULL
cost=txtcost.getText(); //THEN ASSIGN THE COST WITH THE TEXTFIELD VALUE
}
String Updatesql="UPDATE customers SET name='"+name+"',surname='"+surname+"',street='"+street+"',city='"+city+"',mobile='"+mobile+"',phone='"+phone+"',next_service='"+serviceDate+"',cost='"+cost+"' WHERE id='"+lblID.getText()+"'";
int rows=pst.executeUpdate(Updatesql);
JOptionPane.showConfirmDialog(rootPane,"Updated","Message",JOptionPane.DEFAULT_OPTION);
}catch(SQLException e){
JOptionPane.showConfirmDialog(rootPane, e,"Message",JOptionPane.DEFAULT_OPTION);
}
con.CloseMySQLConn(pst, conn);
AllCustomers();
}
TABLE MOUSE CLICK CODE
private void Customers_TableMouseClicked(java.awt.event.MouseEvent evt) {
try{
int row=Customers_Table.getSelectedRow();
String table_click=(Customers_Table.getModel().getValueAt(row, 0).toString());
String sql="select * from customers where id="+table_click;
pst=conn.prepareStatement(sql);
rs=pst.executeQuery();
if(rs.next()){
lblID.setText(rs.getString("id"));
txtname.setText(rs.getString("name"));
txtsurname.setText(rs.getString("surname"));
txtstreet.setText(rs.getString("street"));
txtcity.setText(rs.getString("city"));
if((rs.getString("next_service")!=null)){
NextServiceDate.setDateFormatString(rs.getString("next_service"));
}
txtmobile.setText(rs.getString("mobile"));
txtphone.setText(rs.getString("phone"));
txtcost.setText(rs.getString("cost"));
}
}catch(SQLException e){
JOptionPane.showMessageDialog(rootPane, e);
}
}
在应用程序中我保存客户个人信息和下一个服务的日期和成本。所以我将jdatechooser日期转换为(yyyy-mm-dd),以便我可以与当前系统日期进行比较并显示一条消息必须告知客户他们的汽车服务。 这是一个小应用程序,只是为了存储我的客户,我努力解决出现的问题。 提前谢谢。