嘿伙计们,这是我将名称与数据库中已有的名称进行比较的代码。但是 getcount 始终返回 0。有什么帮助吗?谢谢 !!
public String checkUserName(SQLiteDatabase db, String enteredName)
{
String selectionArgs[] = new String[1];
selectionArgs[0] = enteredName;
Cursor cursor = db.rawQuery("select * from table1 where user=?", selectionArgs);
cursor.moveToFirst();
return Integer.toString(cursor.getCount());
}
我用来调用上述函数的代码是:
Intent intent = getIntent();
TextView tv1 = new TextView(this);
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE)
tv1.setText(db.checkUserName(db.getWritableDatabase(), message));
relativeLayout.addView(tv1)
数据库快照链接:http: //i.stack.imgur.com/LnTbl.jpg