2 xiangwei132 xiangwei132 于 2016.04.12 22:34 提问

android SQLite向表中插入数据的问题 5C

package com.example.xiangwei;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.test.AndroidTestCase;

public class TestCase extends AndroidTestCase {
private MyOpenHelper oh;
private SQLiteDatabase db;
public void test(){
//getContext():获取一个虚拟的上下文
MyOpenHelper oh = new MyOpenHelper(getContext(), "xiangwei.db", null, 1);
SQLiteDatabase db = oh.getWritableDatabase();
}
@Override
protected void setUp() throws Exception {
// TODO Auto-generated method stub
super.setUp();
oh = new MyOpenHelper(getContext(), "xiangwei.db", null, 1);
db = oh.getWritableDatabase();
System.out.println("执行了setup");
}

protected void insert(){
    db.execSQL("insert into person (name,salary,phone)values(sdaio,1234,124)");
    db.execSQL("insert into person (name, salary, phone)values(?, ?, ?)", new Object[]{"小志", 14000, "13888"});
    System.out.println("向伟");
}


protected void tearDown() throws Exception {
    // TODO Auto-generated method stub
    super.tearDown();
    System.out.println("执行关闭数据库");
    db.close();
}

}
可以向数据库中新建表,但一直执行不了insert方法,一直报
Error opening trace file: No such file or directory (2)

4个回答

CSDNXIAON
CSDNXIAON   2016.04.12 22:42

android 中SQLite数据库插入多条数据提高效率
----------------------同志你好,我是CSDN问答机器人小N,奉组织之命为你提供参考答案,编程尚未成功,同志仍需努力!

devmiao
devmiao   Ds   Rxr 2016.04.12 23:51
lxk_1993
lxk_1993   Rxr 2016.04.13 08:37
dongfeng9ge
dongfeng9ge   Ds   Rxr 2016.05.27 17:11

楼主你可以用GreenDAO或者ORMLite

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!