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();
반응형
'개발자료 > Android' 카테고리의 다른 글
안드로이드 Platform Version(OS Version) - API Level 테이블 (0) | 2020.07.09 |
---|---|
[Exception] Synchronous ResponseHandler used in AsyncHttpClient. (0) | 2020.07.07 |
JSONUP (0) | 2020.05.11 |
ListView Divider 제거 (0) | 2017.03.16 |
Firebase 클라우드메시징 서버키 확인방법 (0) | 2017.02.06 |