码迷,mamicode.com
首页 > 移动开发 > 详细

Android 数据库 SQLiteOpenHelper

时间:2019-11-15 20:28:16      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:cto   view   alt   name   static   图片   har   span   oid   

public class DbOpenHelper extends SQLiteOpenHelper {

    private static String name = "test.db"; /* 数据库名称 */
    private static int version = 1; /* 数据库版本号 */

    public DbOpenHelper(Context context) {
        super(context, name, null, version);
        // TODO Auto-generated constructor stub
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub

        String sql = "create table person(id integer primary key autoincrement, name varchar(64))";
        db.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub

    }
}
private Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button = (Button) this.findViewById(R.id.button);

        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                DbOpenHelper dbOpenHelper = new DbOpenHelper(MainActivity.this);
                dbOpenHelper.getWritableDatabase();
            }
        });
    }

技术图片

Android 数据库 SQLiteOpenHelper

标签:cto   view   alt   name   static   图片   har   span   oid   

原文地址:https://www.cnblogs.com/zhangxuechao/p/11869239.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!