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); } }
时间: 2024-10-01 22:59:24