import android.content.Context;
import android.database.DatabaseErrorHandler;
import android.database.sqlite.sqliteDatabase;
import android.database.sqlite.sqliteDatabase.CursorFactory;
import android.database.sqlite.sqliteOpenHelper;
public class DatabaseHelper extends sqliteOpenHelper {
static String dbName = "user.db";
static int version = 1;
// 创建数据库
public DatabaseHelper(Context context) {
super(context,dbName,null,version);
}
@Override
public void onCreate(sqliteDatabase arg0) {
String sql = "CREATE TABLE person (personid integer primary key autoincrement,name varchar(20),age int)";
arg0.execsql(sql);
public void onUpgrade(sqliteDatabase arg0,int arg1,int arg2) {
// TODO Auto-generated method stub
package com.example.createdb;
import android.test.AndroidTestCase;
public class TestDB extends AndroidTestCase {
public void testDBCreate() throws Throwable{
DatabaseHelper dbh=new DatabaseHelper(this.getContext());
dbh.getWritableDatabase();//创建数据库
} 原文链接:https://www.f2er.com/sqlite/201556.html