vaadin 中的数据库 table 更新

Database table update in vaadin

我正在使用以下代码使用以下代码更新我的数据库 table。数据库连接已建立,未显示异常,但我的数据库 table 未更新。

private void setupSaveButton(){
saveButton.addClickListener(new Button.ClickListener() {            

@Override
public void buttonClick(ClickEvent event) {

   try {                       
    String updateQuery = "UPDATE " + MySqlConnectionManager.getDatabaseTableName()
    + " SET  BUGID='" + bugIdTextField.getValue()                                   
     + "', USERID='" + userIdTextField.getValue()
    + "', SUBJECT='" + subjectTextField.getValue()                                
    + "', COMMENT='" + commentTextArea.getValue() 
    + "', STATUS='" + statusComboBox.getValue()
    + "', OWNER='" +ownerTextField.getValue()
    + "', PRIORITY='" + priorityComboBox.getValue()                                
    + "' WHERE DATE='"+dateTextField.getValue()+"'; ";


        Connection connection = MySqlConnectionManager.getInstance().getConnection();
         if(connection!=null){
        Statement stmt = connection.createStatement();
        System.out.println("Query " + updateQuery);
        stmt.executeUpdate(updateQuery);
        }              
    } catch (SQLException ex) {
        Logger.getLogger(BugDetailDisplay.class.getName()).log(Level.SEVERE, null, ex);
    }
  }

 });

我猜你用的是 DateField 作为日期。

MySql 的默认日期格式是 YYYY-MM-DD 而您的 dateTextField.getValue() 将 return Date 对象和 toString 的默认表示13=] 将在您的 query.So 中串联,两种格式不同,您的查询执行成功但无法检测到您从 dateTextField 获得日期的行。您可以使用 SimpleDateFormat 来格式化dateTextField.getValue() 的结果允许查询找到匹配的行。


如果您使用的是简单的 textField,请确保您的日期格式必须与 MySql 日期匹配。