SQLiteDatabase 관련

<database에 삽입시에 where 조건문 정하기>

String[] tableColumns = new String[] {
“(SELECT max(column1) FROM table2) AS max”
String whereClause = “column1 = ? OR column1 = ?”;
String[] whereArgs = new String[] {
String orderBy = “column1”;
Cursor c = sqLiteDatabase.query(“table1”, tableColumns, whereClause, whereArgs,
null, null, orderBy);



<datebase에서 수정시>

String where = “id=?”;
String[] whereArgs = new String[] {String.valueOf(id)};

db.update(DATABASE_TABLE, dataToInsert, where, whereArgs);
<데이터 가져올때 반복문 사용시>

while 사용하고 안에서 data를 가져오면 된다.
try (Cursor cursor = db.rawQuery(…)) {
while (cursor.moveToNext()) {



<특정 값 삭제하기>

SQLiteDatabase db = getReadableDatabase();
String delete = “DELETE from ” + DB_table
+ ” WHERE id=” + id1;



위보다는 아래가 적용이 된다


db = weeklyInfoHelper.getWritableDatabase();
db.delete("weeklyweather", "firstDayofWeek=?", new String[]{"2017년 09월 19일"});

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s