0

私のdb androidにユーザーが登録されているかどうかを確認しようとしています。私はdbを作成し、ユーザーが登録されているかどうかを確認するためのメソッドを持っているこのクラスを持っています:

    public boolean isRegistered(String username, String password) {
          boolean in = false;
          Cursor cursor = db.query(TABLE_NAME_USER, new String[] {USERNAME,PASSWORD},
            USERNAME + " = '" + username + "' AND " + PASSWORD + "= '" + password+"'",
            null, null, null, null);

          if(cursor.moveToFirst())
                  in=true;
          if(!cursor.isClosed())
                  cursor.close();
   return in;
   }

このメソッドを実行すると、アプリケーションがクラッシュします。なんで?手伝って頂けますか?

4

1 に答える 1

0

その代わりに、単純なクエリをデータベースに渡して、そこからユーザー数を取得できます。このように。

 public static SQLiteDatabase Objdatabase;

 SQLiteStatement stmtSelectRec=Objdatabase.compileStatement("Select count(0) from table where username='abc' and password='123'");  

 int countnumber=(int)stmtSelectRec.simpleQueryForLong();

 if(countnumber)>0?True:false.
于 2013-06-04T10:38:52.813 に答える