java – 在android中更新sqlite db的首选方法

在android中使用db.update的哪种方式更快更好?即:构造整个where子句字符串以及where子句变量值或通过将where子句变量值作为字符串数组传递来使用第4个参数进行更新?
传递where子句变量值作为新的字符串数组是否可以防止sql注入攻击?
public boolean UpdateChannelSortKey(Channel c)
{
ContentValues cv = new ContentValues();
cv.put("SortKey", c.SortKey);
return this.db.update("Channels", cv, "ChannelID = ?", new String[]{String.valueOf(c.ChannelID)}) > 0;
}
要么
public boolean UpdateChannelSortKey(Channel c)
{
ContentValues cv = new ContentValues();
cv.put("SortKey", c.SortKey);
return this.db.update("Channels", cv, "ChannelID = " + c.ChannelID, null) > 0;
}
解决方法:
第一种方式更可取,因为:
1)是的,它可以防止SQL注入攻击.
2)最好总是使用准备好的语句 – 不仅仅是在android中,所以你会养成一个好习惯.
3)恕我直言,它具有更高的可读性.