Android新建数据库和建表demo
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android新建数据库和建表demo相关的知识,希望对你有一定的参考价值。
public class DBHelper extends SQLiteOpenHelper{ public final static String DATABASENAME ="diaryOpenHelper.db"; public final static int DATABASEVERSION =1; //创建数据库 public DBHelper(Context context,Stringname,CursorFactory factory,int version){ super(context, name, factory,version); } //创建表等机构性文件 public void onCreate(SQLiteDatabase db){ String sql ="create tablediary"+"("_id integer primary key autoincrement,"+"topic varchar(100),"+"content varchar(1000)"+")"; db.execSQL(sql); } //若数据库版本有更新,则调用此方法 public void onUpgrade(SQLiteDatabase db,int oldVersion,int newVersion){ String sql = "drop table ifexists diary"; db.execSQL(sql); this.onCreate(db); } }