我有两个值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你的帮助我已经知道如何处理它: –