0

嘿伙计们,这是我将名称与数据库中已有的名称进行比较的代码。但是 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

4

1 回答 1

1

发现哪里不对了。。

修改代码为:

Cursor cursor = db.rawQuery("select * from table1 where user like ?", selectionArgs);

在 sqlite 中使用 LIKE,'string%' 用于比较两个列条目除了上述方法

于 2013-07-12T17:58:34.253 回答