- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想多次将记录插入表中,我可以选择使用 compileStatement 或使用 db.insert,如下所示。
String TABLENAME = "table"; //fields in table: id, name
SQLiteStatement statement = db.compileStatement("INSERT INTO "+TABLENAME+" VALUES(?,?);");
statement.bindLong(1,666);
statement.bindString(2,"john");
statement.executeInsert();
或
String TABLENAME = "table";
ContentValues values = new ContentValues();
values.put("id", 666);
values.put("name", "john");
db.insert(TABLENAME, null, values);
哪个应该是最佳的?
编辑:-我正在运行的应用程序是单线程的。
最佳答案
insert()
在每次调用时编译 SQL,而 compileStatement()
方法仅编译一次 SQL。当多次使用具有不同绑定(bind)参数的相同 SQL 时,compileStatement()
方法做的工作更少,速度更快。
此外,考虑将插入包装在事务中以减少等待 I/O 的时间。
关于android - android 中的 compileStatement 或 db.insert,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22221086/
我在 groovy 中有以下代码: class Test { List yo(boolean x) { List res = x ? [] : [1, 2, 3] } } 在我向类添加
我是第一次使用 @CompileStatic,并且对 Groovy 的映射构造函数在这种情况下如何工作感到困惑。 @CompileStatic class SomeClass { Long i
有没有一种方法可以将@ TypeChecked,@ GrailsCompileStatic,@ CompileStatic的功能添加到整个grails项目中? 为了解释我现在正在处理的代码,我希望编译
为什么只用@CompileStatic 注释会使下面的代码给出 NullPointerException? class GroovyEach { static def main(args) {
当我们对任何特定类(如 RESTClient)使用 someClass.metaClass.constructor 时,在用 @CompileStatic 注释的类的方法中可用,构造函数覆盖根本不起作
当我查看使用 @groovy.transform.CompileStatic 编译的 Groovy 脚本的字节码时,我看到一些奇怪的结果 这是重复问题的最简单的类: @groovy.transform
我不确定这是否已经可行,但是否可以在普通的 groovy 脚本上使用 @CompileStatic 而无需将脚本包装在类中? 我正在使用 GroovyClassLoader 来动态解析和编译脚本,所以
有人可以解释@TypeChecked 和@CompileStatic 之间的区别吗? 我用@TypeChecked 读到它不可能在运行时添加新方法。 哪些其他功能是不允许的? @CompileStat
我在服务方法上添加了两个注解,编译后发现方法被编译成一个新的类文件,我反编译生成的类文件,发现@CompileStatic 没有按预期工作。 是正确的还是 grails 的错误? class Foob
我有一个类,其闭包定义为: void everyPixel( closure ){ for( def x : 0..width-1 ) for( def y : 0..heig
我读过这个:http://docs.groovy-lang.org/latest/html/gapi/groovy/transform/CompileStatic.html ,这个:Should I
我想多次将记录插入表中,我可以选择使用 compileStatement 或使用 db.insert,如下所示。 String TABLENAME = "table"; //fields in tab
我已经阅读了 "What's new in Groovy 2.0"我对何时使用@CompileStatic 有点困惑。文章提到@CompileStatic为无法利用 Java7 的调用动态部分的开发人
在 Groovy 中,可以简单地通过将变量本身放在 if 中来测试集合是否为 null 和 empty: def collection = [ 'test' ] if(!collection) {
我是新手 groovy 程序员,我遇到了带有静态编译的 switch-case-break 语句的奇怪行为(@CompileStatic 注释)。看来break s 被忽略。 这是一个错误还是我在阅读
我是一名优秀的程序员,十分优秀!