Android 创建DBHelper类

public class DBHelper extends SQLiteOpenHelper {

    private static int mVersion = 1;
    private static String name = "apps.db";

    public DBHelper(Context context) {
        super(context, name, null, mVersion);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql = "create table book(_id int primary key autoincrememt, name varchar(32) ,price double , publishtime date)";
        db.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        String sql = "DROP TABLE IF EXISTS book";
        db.execSQL(sql);
        this.onCreate(db);
    }

}

你可能感兴趣的:(android)