2013-06-04 1 views
0

내 db 안드로이드에 사용자가 등록되어 있는지 확인하려고합니다. 이 클래스는 db를 만들고 사용자가 등록되어 있는지 확인하는 방법을 가지고 있습니다.android의 메소드 쿼리로 크래시

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; 
    } 

이 메서드를 실행하면 응용 프로그램이 중단됩니다. 왜? 나 좀 도와 줄 수있어?

+0

초기화 된 데이터베이스? – Raghunandan

+2

당신의 logcat을 넣어 ... – Riser

답변

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. 
+0

Egual. 내 휴대 전화에 데이터베이스가 표시되지 않지만 새 사용자를 추가하면 데이터베이스에 새 사용자를 추가하는 기능이 중단되지 않습니다 ...하지만이 기능은 중단됩니다! –