Java 在android中更新sqlite db的首选方法
在android中,使用db.update的哪种方式更快更好?ie:构造整个where子句字符串以及where子句变量值,或者通过将where子句变量值作为字符串数组传递来使用第四个参数进行更新 将where子句变量值作为新字符串数组传递是否可以防止sql注入攻击Java 在android中更新sqlite db的首选方法,java,android,performance,sqlite,sql-injection,Java,Android,Performance,Sqlite,Sql Injection,在android中,使用db.update的哪种方式更快更好?ie:构造整个where子句字符串以及where子句变量值,或者通过将where子句变量值作为字符串数组传递来使用第四个参数进行更新 将where子句变量值作为新字符串数组传递是否可以防止sql注入攻击 public boolean UpdateChannelSortKey(Channel c) { ContentValues cv = new ContentValues(); cv.put("
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;
}
或
第一种方法更可取,因为: 1) 是的,它可以防止sql注入攻击 2) 最好总是使用事先准备好的语句,而不仅仅是android,这样你就会养成一个好习惯 3) 依我看,它具有较高的可读性
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;
}