3 回答

TA貢獻2019條經驗 獲得超9個贊
使用 a 和綁定參數;您當前的方法容易受到 sql 注入的影響。忽略這種擔憂(這是一個很大的問題),你沒有引用你的參數。你可以做PreparedStatement
String query4 = MessageFormat.format(
"UPDATE system_object SET file_path = '{0}', validate='{1}' " +
"where category_key = 2", settings.getAntivirus_filePath(),
settings.isAntivirus_validate());

TA貢獻1813條經驗 獲得超2個贊
將代碼修改為:
String query4 = MessageFormat.format(
"UPDATE system_object SET file_path = \"{0}\", validate=\"{1}\" " +
"where category_key = 2", "demo1",
"demo2");
System.out.println(query4);
輸出:UPDATE system_object SET file_path = "demo1", validate="demo2" where category_key = 2

TA貢獻1829條經驗 獲得超13個贊
只是一個更新使用雙''而不是單':
String query4 = MessageFormat.format(
"UPDATE system_object SET file_path = '{0}', validate='{1}' " +
"where category_key = 2", settings.getAntivirus_filePath(),
settings.isAntivirus_validate());
添加回答
舉報