android 数据库

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class StudentDBHelper extends SQLiteOpenHelper {

    private static SQLiteDatabase db = null;
    private static final String TAG = "StudentDB";
    private static final String DATABASE_NAME = "studentss.db";
    private static final int Version = 1;
    public static final String TABLE_NAME = "STUDENT_TABLE";
    private static final String base_info = "create table "
            + TABLE_NAME
            + "(name text not null,sex text,age text,no text,phone text,address text);";

    private StudentDBHelper(Context context) {
        super(context, DATABASE_NAME, null,
                Version);
        Log.i(TAG, "database is create");        
    }

    public static SQLiteDatabase getSQLiteDatabse(Context context) {
        db = new StudentDBHelper(context).getWritableDatabase();        
        return db;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(base_info);
    }

    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.i(TAG, "onUpgrade database");
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
        onCreate(db);
    }
    
}

你可能感兴趣的:(android,String,table,null,database,import)