【问题标题】:Database table update in vaadinvaadin 中的数据库表更新
【发布时间】:2015-01-05 12:56:57
【问题描述】:

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

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);
    }
  }

 });

【问题讨论】:

    标签: java mysql database sql-update vaadin


    【解决方案1】:

    我猜你正在使用DateField 作为日期。

    MySql 的默认日期格式是YYYY-MM-DD,而您的dateTextField.getValue() 将返回Date 对象,而Date 的默认toString 表示将在您的查询中连接起来。因此,两种格式都不同,您的查询将执行成功但无法检测到您从dateTextField 获得的日期行。您可以使用SimpleDateFormat 格式化dateTextField.getValue() 的结果以允许查询找到匹配的行。


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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多