Java vaadin中的数据库表更新
我使用下面的代码来更新我的数据库表。数据库连接已建立,未显示异常,但我的数据库表未更新Java vaadin中的数据库表更新,java,mysql,database,sql-update,vaadin,Java,Mysql,Database,Sql Update,Vaadin,我使用下面的代码来更新我的数据库表。数据库连接已建立,未显示异常,但我的数据库表未更新 private void setupSaveButton(){ saveButton.addClickListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { try { String update
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()
将返回date
对象,并且date
的默认toString
表示将在您的查询中串联。因此,这两种格式不同,您的查询执行成功,但无法检测到从dateTextField
获取的日期行。您可以使用SimpleDateFormat
格式化dateTextField.getValue()
的结果,以允许查询查找匹配的行
如果您使用的是simple
textField
,请确保您的日期格式必须与MySql日期匹配