0

我的 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();
}   

表鼠标点击代码

 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),这样我就可以与当前系统日期进行比较,并显示一条消息,哪些客户必须是通知他们的汽车服务。这是一个小应用程序,只是为了存储我的客户,我努力解决出现的问题。提前致谢。

4

0 回答 0