2012-02-06 200 views
0

我想实现下面的代码空...存储在SQLite数据库为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(int类型)的初始值是零。它实际上是将null转换为to.String

当我尝试运行它给出空指针的错误。

我想在数据库中存储空值,请告诉我该怎么做。

最好的问候

回答

1

用途:

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

确定我这样做,但现在表示,在指数4绑定值为null。任何想法? – 2012-02-06 06:23:00

0

为什么你不检测它是否为空。如果它为空,则在数据库中插入“null”。