2014-01-20 3 views
0

나는 안드로이드 응용 프로그램에서 작업 중이며 두 개의 문자열이 내 SQL 쿼리의 WHERE 상태에 있습니다.문자열 조건 SQllite에서 조건

 String query=" SELECT * FROM "+USER_TABLE+" where Username=? COLLATE NOCASE and Password=?"; 
    Cursor logincursor= database.rawQuery(query, new String[]{username,password}) 
if (logincursor.moveToFirst()) { 

      user.UserName = logincursor.getString(logincursor 
        .getColumnIndex("Username")); 
      user.Password =new EncryptDecrypt().decrypt(logincursor.getString(logincursor 
        .getColumnIndex("Password"))); 
      user.FullName = logincursor.getString(logincursor 
        .getColumnIndex("Fullname")); 
      user.UserID = logincursor.getInt(logincursor 
        .getColumnIndex("UserID")); 
      user.EmployeeID = logincursor.getInt(logincursor 
        .getColumnIndex("EmployeeID")); 

     } 

내 안드로이드 응용 프로그램에서이 작업을 수행 할 수있는 좋은 방법을 제안하십시오 :

내 코드입니다.

+0

문제는 무엇인가? – laalto

+0

String을 where 조건으로 사용할 때 내 앱에서 값을 얻지 못합니다. – Arun

+1

질문에 관련 코드를 추가하는 것이 좋습니다. 게시 한 SQL에 아무런 문제가 없습니다. – laalto

답변

0

아래 쿼리를 사용하십시오.

db.rawQuery("select * from login_table where username =" + "\""+ username.trim() + "\""+" and password="+ "\""+ password.trim() + "\""+, null); 

또는

db.query(USER_TABLE, new String[] {"*"}," Username = ? and Password =?", new String[]{username,password}, null, null, null); 
+1

username이''OR 1 = 1;': – laalto