xiangwei132
xiangwei132
2016-04-12 14:34

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

5
  • android

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条回答