我有兩個值picId
和tubId
我想更新表A.但首先,我必須檢查它們是否是空的,即""
。我使用兩次更新語句。我想知道是否只能使用update語句來完成此任務。Oracle11g sql可以更新語句判斷一些列是「」
String picId = "";
String tubId = "1";
if(!"".equals(picId)) {
String update = "update A set columnName=someValue where id=" + picId;
//this method for update
this.executeUpdate(update, new Object[]{});
}
if(!"".equals(tubId)) {
String update = "update A set columnName=someValue where id=" + tubId;
this.executeUpdate(update, new Object[]{});
}
非常感謝!
此代碼易受SQL注入攻擊。 [使用PreparedStatements代替](https://stackoverflow.com/questions/1812891/java-escape-string-to-prevent-sql-injection)。 – Michael
謝謝all.WIth你的幫助我已經知道如何處理它: –