Android 기반의 프로그램을 작성시 데이터베이스를 기본적으로 Sqlite를 사용하게 된다.
그러나, 개발 과정 중에 데이터베이스의 변경이 발생하였을 경우에는 아래와 같이 수정하여
재배포하면 된다.
package com.cheongju.sqlite; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; public class DBManager extends SQLiteOpenHelper { final static String DB_NAME = "sample.db"; final static int DB_VERSION = 1; /*-- 업그레이드를 필요로 할 경우에 버전의 값을 올려주면 된다. --*/ public DBManager(Context context) { super(context, DB_NAME, null, DB_VERSION); // TODO Auto-generated constructor stub } @Override public void onCreate(SQLiteDatabase arg0) { Log.d("DEBUG ==> ", "Table Upgrade ........ "); // TODO Auto-generated method stub arg0.execSQL("Create table sample ( sample_id text, sample_date text, sample_name text);"); /*-- 샘플데이터 등록 --*/ arg0.execSQL("insert into sample (sample_no, sample_date, sample_name) values('20111201130101','20111230'"); } @Override public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) { // TODO Auto-generated method stub arg0.execSQL("drop table sample;"); Log.d("DEBUG", "Table Upgrade Drop "); onCreate(arg0); } }
'프로그래밍' 카테고리의 다른 글
티스토리 syntaxhighlighter 적용하기 (0) | 2012.01.12 |
---|