[英]Storing Null in SQlite Database for Android
i am trying to implement following Code... 我正在尝试实现以下代码...
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(),
});
Now the initial value of parentAccoudId (Type int ) is null. 现在parentAccoudId(Type int)的初始值为null。 It is actually converting null to to.String 它实际上是将null转换为to.String
When i try to run it gives error of Null pointer. 当我尝试运行时,会给出Null指针错误。
I want to store null value in database please tell me how can i do that. 我想在数据库中存储空值,请告诉我该怎么做。
Best Regards 最好的祝福
Use: 采用:
account.parentAccountId != null ?
integerToDB(account.parentAccountId).toString() : "null"
Why don't you just detect if its null. 您为什么不只检测它是否为null。 If it is null then insert "null" into the database. 如果为null,则将“ null”插入数据库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.