728x90
SQLiteDB에 있는 자료를 읽어서 HashMap 메모리 상에 올리는 예제이다.
HashMap<String, SQLite_Item> sqliteDBMap = new HashMap<String, SQLite_Item>();
public void SQLiteDB2ArrayList(){
sqliteDBMap.clear(); // 메모리 초기화
sqLiteDBHandler = new SQLiteDBHandler(Main.this);
SQLiteDatabase db = sqLiteDBHandler.getReadableDatabase();
db.beginTransaction();
Cursor cursor = sqLiteDBHandler.LoadSQLiteDBCursor();
try {
cursor.moveToFirst();
System.out.println("SQLiteDB 개수 = " + cursor.getCount());
while (!cursor.isAfterLast()) {
SQLite_Item item = new SQLite_Item();
item.setIdx(cursor.getString(0));
item.setUserNM(cursor.getString(1));
item.setMobileNO(cursor.getString(2));
item.setTelNO(cursor.getString(3));
item.setTeam(cursor.getString(4));
item.setPosition(cursor.getString(5));
item.setCheckState(cursor.getInt(6));
// HashMap 에 추가
sqliteDBMap.put(cursor.getString(0), item);
cursor.moveToNext();
}
db.setTransactionSuccessful();
} catch (Exception e) {
e.printStackTrace();
} finally {
cursor.close();
db.endTransaction();
}
}
HashMap<String, SQLite_Item> sqliteDBMap = new HashMap<String, SQLite_Item>();
public void SQLiteDB2ArrayList(){
sqliteDBMap.clear(); // 메모리 초기화
sqLiteDBHandler = new SQLiteDBHandler(Main.this);
SQLiteDatabase db = sqLiteDBHandler.getReadableDatabase();
db.beginTransaction();
Cursor cursor = sqLiteDBHandler.LoadSQLiteDBCursor();
try {
cursor.moveToFirst();
System.out.println("SQLiteDB 개수 = " + cursor.getCount());
while (!cursor.isAfterLast()) {
SQLite_Item item = new SQLite_Item();
item.setIdx(cursor.getString(0));
item.setUserNM(cursor.getString(1));
item.setMobileNO(cursor.getString(2));
item.setTelNO(cursor.getString(3));
item.setTeam(cursor.getString(4));
item.setPosition(cursor.getString(5));
item.setCheckState(cursor.getInt(6));
// HashMap 에 추가
sqliteDBMap.put(cursor.getString(0), item);
cursor.moveToNext();
}
db.setTransactionSuccessful();
} catch (Exception e) {
e.printStackTrace();
} finally {
cursor.close();
db.endTransaction();
}
}
sqLiteDBHandler = new SQLiteDBHandler(context); // BroadcastReceiver 에서 사용할 때
728x90
'안드로이드 > Android SQLite' 카테고리의 다른 글
안드로이드 메모 어플 소스 RecyclerView + SQLite 활용 (0) | 2019.09.26 |
---|---|
android 메모 어플 소스 ListView + SQLite 활용 (0) | 2019.09.24 |
Android SQLite Database 지식 (0) | 2017.06.02 |
Android Studio SQLite - SQLiteOpenHelper 를 사용하는 방법 (0) | 2017.05.29 |
안드로이드 Preference (환경설정 저장) (0) | 2016.06.25 |