openHelper썼을 때의 장점

1. 읽기전용, 쓰기전용 구분해서 디비를 오픈 가능

2. 버전 업그레이드를 손쉽게 처리

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
 
public class PersonDBOpenHelper extends SQLiteOpenHelper{
 
    private static final String DBNAME = "person.db";
    public PersonDBOpenHelper(Context context,int version) {
        super(context, DBNAME, 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 text,"
                + "phoneNum text,"
                + "age integer,"
                + "gender integer"
                + ");";
        db.execSQL(sql);
        ContentValues values = new ContentValues();
        values.put("name""도우휘");
        values.put("phoneNum""010-0101-1001");
        values.put("age"26);
        values.put("gender"0);
        db.insert("person"null, values);
        values.put("name""크로우걸");
        values.put("phoneNum""010-0202-2002");
        values.put("age"26);
        values.put("gender"1);
        db.insert("person"null, values);
    }
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // TODO Auto-generated method stub
        String sql = "drop table if exists person";
        db.execSQL(sql);
        
        onCreate(db);
    }
 
}
 
cs


' IOT 기반 응용 SW과정 > Android, Arduino' 카테고리의 다른 글

Day101  (0) 2016.08.10
Day99 안드로이드 파일 복사  (0) 2016.08.08
Day98 안드로이드 db Select문  (0) 2016.08.05
Day97  (0) 2016.08.04
Day95  (0) 2016.08.02

+ Recent posts