我有一個簡單的準備語句來更新MySQL數據庫中的記錄。表格,列,目標屬性和信息都來自文本字段。首先,我沒有準備好聲明,但是如果用戶選擇插入引號或其他符號,程序很容易破壞。準備語句中的Mysql語法錯誤
現在即時得到這樣的:
更新客戶端設置 'FULL_NAME'= Martinajh WHERE ID ='5'com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:你 在你的SQL錯誤句法;檢查對應於 你的MySQL服務器版本正確的語法近 'selectedTable2' SET 'namec'= 'cellValue' WHERE ID = = 5' 在行1
String cellValue3 = String.valueOf(table.getValueAt(row, 0));
int id = Integer.parseInt(cellValue3);
String selectedTable2 = (String) listOfTablesNames.getSelectedValue();
String cellValue = String.valueOf(table.getValueAt(row, column));
String namec = table.getColumnName(column);
String query ="UPDATE ? SET ? = ? WHERE id== ?";
PreparedStatement preparedStmt = (PreparedStatement) conn.prepareStatement(query);
preparedStmt.setString (1, "selectedTable2");
preparedStmt.setString(2, "namec");
preparedStmt.setString(3, "cellValue");
preparedStmt.setInt(4, id);
preparedStmt.executeUpdate();
'WHERE id ==?'嘗試在這裏使用一個等號。 –