String new_recorded_lastname="a lastname";
////record to database......
Cursor cursor = db.rawQuery("SELECT lastname FROM people; ",null);
if (cursor != null){
while(cursor.moveToNext()){
String recorded_lastname=cursor.getString(cursor.getColumnIndex("lastname"));
if(!(recorded_lastname.equals(new_recorded_lastname))){
//add new_recorded_lastname to database
break;
}
}
}
我只想在我的数据库中有一个姓氏。即使我使用“if(!(recorded_lastname.equals(new_recorded_lastname)))”检查此行代码,它也会一次又一次地添加相同的记录。如何控制姓氏只添加一次?
//它适用于第一条记录非常好,但是从第二条记录开始,它会一次又一次地添加一些姓氏......