很多时候我们需要在项目进行中为项目添加一张表,今天终于搞清楚了。
代码如下
package com.zy.dao;import androID.R.integer;import androID.R.string;import androID.content.Context;import androID.database.sqlite.sqliteDatabase;import androID.database.sqlite.sqliteDatabase.CursorFactory;import androID.database.sqlite.sqliteOpenHelper;public class DbHelper extends sqliteOpenHelper{ private static final int version = 2; private static final String DBname = "db_fa.db"; public DbHelper(Context context) { super(context,DBname,null,version); } @OverrIDe public voID onCreate(sqliteDatabase db) { //创建收入表 db.execsql("create table if not exists tb_IncomeInfo (income_ID integer primary key autoincrement," + "income_price varchar(10),income_date varchar(20),income_account varchar(10)," + "income_payer varchar(10),income_category varchar(10),income_remark varchar(100))"); //创建支出表 db.execsql("create table if not exists tb_ConsumeInfo (consume_ID integer primary key autoincrement," + "consume_price varchar(10),consume_time varchar(20),consume_account varchar(10)," + "consume_address varchar(20),consume_category varchar(10),consume_remark varchar(100))"); } @OverrIDe public voID onUpgrade(sqliteDatabase db,int oldVersion,int newVersion) { onCreate(db); }}
添加新表后要在onUpgrade执行onCreate方法,并且要把版本号更新(这个很重要!),这里我把版本号改为了。不然是无法添加进去表的!
总结以上是内存溢出为你收集整理的sqlite数据库中SQLiteOpenHelper类的onUpgrade方法全部内容,希望文章能够帮你解决sqlite数据库中SQLiteOpenHelper类的onUpgrade方法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)