· 8 years ago · Feb 28, 2018, 11:46 AM
1package com.project;
2
3import java.io.File;
4
5import android.content.Context;
6import android.database.sqlite.SQLiteDatabase;
7import android.database.sqlite.SQLiteOpenHelper;
8import android.util.Log;
9
10public class DbHelper extends SQLiteOpenHelper {
11
12 private static final String DATABASE_NAME = "file";
13 private static final int DATABASE_VERSION = 1;
14
15 // Database creation sql statement
16 private static final String DATABASE_CREATE = "create table if not exists file (_id integer primary key autoincrement," +
17 "name text not null,"..."emailaddress text not null);";
18
19 public DbHelper(Context context) {
20 super(context, DATABASE_NAME, null, DATABASE_VERSION);
21 }
22
23 // Method is called during creation of the database
24 @Override
25 public void onCreate(SQLiteDatabase database) {
26 database.execSQL(DATABASE_CREATE);
27 }
28
29 // Method is called during an upgrade of the database, e.g. if you increase
30 // the database version
31 @Override
32 public void onUpgrade(SQLiteDatabase database, int oldVersion,
33 int newVersion) {
34 Log.w(DbHelper.class.getName(),
35 "Upgrading database from version " + oldVersion + " to "
36 + newVersion + ", which will destroy all old data");
37 database.execSQL("DROP TABLE IF EXISTS todo");
38 onCreate(database);
39 }
40}