SELECT * FROM TABLE을 하면 DB의 해당 테이블 전체를 가져오는데요
아래와 같이 구현을 합니다.
public ArrayList<ListViewItem> getData() {
ArrayList<ListViewItem> mListArray = null;
SQLiteDatabase db = null;
Cursor c = null;
try {
db = getWritableDatabase();
c = db.rawQuery("SELECT * FROM " + TABLE_SAMP, null);
if (c != null && c.getCount() > 0) {
mListArray = new ArrayList<ListViewItem>();
while (c.moveToNext()) {
ListViewItem model = new ListViewItem();
model.setResId(Integer.parseInt(c.getString(c.getColumnIndex(COL_ID))));
model.setIcon(Integer.parseInt(c.getString(c.getColumnIndex(COL_IMAGE))));
model.setTitle(c.getString(c.getColumnIndex(COL_TITLE)));
model.setDesc(c.getString(c.getColumnIndex(COL_CONTENT)));
model.setFavorite(c.getString(c.getColumnIndex(COL_FAVORITE)));
model.setShop(c.getString(c.getColumnIndex(COL_SHOP)));
mListArray.add(model);
}
}
c.close();
db.close();
db = null;
return mListArray;
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
if (c != null) {
c.close();
c = null;
}
if (db != null) {
db.close();
db = null;
}
}
}
그렇다면 특정열의 값을 가져올라면
SELECT column FROM table where id='1' and name = 'kim' 이렇게 구현을 할려면 어떻게 해야하나요??
해당 컬럼의 id의 column값만 가져오면 됩니다..