Reputation: 15
I was working with the following code to update my database table with the following code. Database connection is established, no exceptions shown, but my database table is not getting updated.
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);
}
}
});
Upvotes: 0
Views: 515
Reputation: 22972
I guess you are using DateField
for date.
Default date format of MySql is YYYY-MM-DD
while your dateTextField.getValue()
will return Date
Object and default toString
representation of Date
will be concatenated in your query.So,both formats are different and your query executes successfully but can not detect the row with date you get from dateTextField
.You can use SimpleDateFormat
to format result of dateTextField.getValue()
to allow query to find matching row.
If you are using simple textField
than make sure your date format must match with MySql date.
Upvotes: 2