SQLiteDatabase 를 이용한 SQLite 사용하기

2020. 5. 21. 07:04개발자료/Android


반응형

1. SQLiteDatabase 생성(Create) 및 열기(Open)

SQLiteDatabase database = openOrCreateDatabase("database.db3", MODE_WORLD_WRITEABLE, null);

2. 쿼리 실행(CREATE, INSERT, UPDATE, DELETE 실행시)

database.beginTransaction();
try{
	database.execSQL(strSQL);
	database.setTransactionSuccessful();
}catch(Exception e){
	e.printStackTrace();
}finally{
    database.endTransaction();
}

3. 쿼리실행(SELECT 실행시)

Cursor cursor = null;
try{
	cursor = database.rawQuery(strSQL, null);
	if(cursor != null){
		while(cursor.moveToNext()){
			String strField0 = cursor.getString(0);
		}
	}
}catch(Exception e){
	e.printStackTrace();
}finally{
	if(cursor != null) cursor.close();
}

4. SQLiteDatabase 종료

database.close();
반응형