2014-02-15 2 views
1

안드로이드를 사용하여 SQLite 데이터베이스에서 null 값을 가져 오는 데 문제가 있습니다.안드로이드 SQLite 데이터베이스에서 null 값을 얻는 방법

내 데이터베이스에는 10 개의 열이 있습니다. 1 열에서 8 열까지 모두 값으로 채워집니다. 그러나 열 9와 열 10의 값이 null 또는 일부 숫자 인 여러 행이 있습니다.

String selectQuery = "SELECT * FROM products WHERE barcodeId='" + id + "'"; 

Cursor myCursor = db.rawQuery(selectQuery, null); 
if (myCursor.moveToFirst()) { 

    //checking to see if there is something in column 9 
    if(myCursor.getString(8) != null){ 
     // do soemthing 
    }else { 
     // if there is nothing do something 
    } 

    //checking to see if there is something in column 10 
    if(myCursor.getString(9) != null){ 
     // do soemthing 
    }else { 
     // if there is nothing do something 
    } 
} 

어떤 사람이 내 테이블의 컬럼 9, 10 내 예에 따라 작동하는 코드를 제공 할 수 있습니다 :

나는 확인하고 싶다.

간략한 설명도 환영합니다. 감사합니다.

답변

3

Cursor.getString()이 null을 반환하는지 여부는 알 수 없습니다. 워드 프로세서는 말하지 않는다. 그냥 빈 문자열을 반환 할 수도있다. 대신에 열의 Null 값을 확인하려면 Cursor.isNull()을 사용해야합니다.

1

감사합니다. DavidCAdams 내 문제가 해결되었습니다.

누군가 내 관심이 있다면 여기에 내 코드가 있습니다.

if(myCursor.isNull(8)){ 
    Log.w("No value", "Cell is empty"); 
}else{ 
    Log.w("Value is present", "There is a value"); 
} 

if(myCursor.isNull(9)){ 
    Log.w("No value", "Cell is empty"); 
}else{ 
    Log.w("Value is present", "There is a value"); 
} 
+0

welcome to stackoverflow –

관련 문제