你有参数化查询太...少的方式来实现这一目标:
ContentValues vals = new ContentValues();
vals.putString("ColumnName", htmlString);
db.insert("myTable", null, vals);
或
final SQLiteStatement insert = db.compileStatement("INSERT INTO myTable VALUES (?)");
insert.bindString(1, htmlString);
//edit: hehe forgot about most important thing
insert.executeInsert();
或
db.rawQuery("INSERT INTO myTable VALUES (?)", new String[] {htmlString});
编辑:(插入多行)
如果你瓦纳插入多1行,然后做在交易(应该是更快) 和喜欢第二个解决方案:
db.beginTransaction();
try {
final SQLiteStatement insert = db.compileStatement("INSERT INTO myTable VALUES (?)");
for(...){
insert.clearBindings();
insert.bindString(1, htmlString[N]);
//edit: hehe forgot about most important thing
insert.executeInsert();
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
谢谢! db.rawQuery与db.execSQL一样只是参数?另外,在你提供的3个例子中,你是否赞成其中的任何一个?如果是这样,为什么? – PaulG
execSQL不应该用于SELECT/INSERT/UPDATE/DELETE ...如果你只需要1行然后选择其中的3个(真的无所谓),如果你插入多行然后看我的编辑 – Selvin