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)

2个回答

楼主你可以用GreenDAO或者ORMLite

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问