簡體   English   中英

在Android的SQlite數據庫中存儲Null

[英]Storing Null in SQlite Database for Android

我正在嘗試實現以下代碼...

String updateQuery ="INSERT INTO MAAccounts(userId, accountId, accountType, accountName, parentAccountId ) VALUES(?, ?, ?, ?, ?)"; 


        Cursor c = mDb.rawQuery(updateQuery, new String[]{
                stringToDB(account.userId),
                integerToDB(account.accountId).toString(),
                integerToDB(account.accountType.getValue()).toString(),
                stringToDB(account.accountName),
                integerToDB(account.parentAccountId).toString(),
                });

現在parentAccoudId(Type int)的初始值為null。 它實際上是將null轉換為to.String

當我嘗試運行時,會給出Null指針錯誤。

我想在數據庫中存儲空值,請告訴我該怎么做。

最好的祝福

采用:

account.parentAccountId != null ? 
  integerToDB(account.parentAccountId).toString() : "null"

您為什么不只檢測它是否為null。 如果為null,則將“ null”插入數據庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM