I am trying to store a null value into the database but everytime I load the value I get 0.
I declare the field just like "intVal integer"
This is how I retrieve it:
Integer x;
x = cursor.getInt(cursor.getColumnIndexOrThrow(MyDBAdapter.KEY_X));
Is that reliable? or is it undefined?
So it seems to me one cannot save null as an undefined integervalue
Many thanks
解决方案Returns the value of the requested column as an int.
The result and whether this method throws an exception when the column value is null, the column type is not an integral type, or the integer value is outside the range [Integer.MIN_VALUE, Integer.MAX_VALUE] is implementation-defined.
So, it's an implementation detail which you shouldn't rely on.
You can still get the effect you want, though: you simply do the null check before you read the value.
int index = cursor.getColumnIndexOrThrow(MyDBAdapter.KEY_X);
Integer x = null;
if (!cursor.isNull(index)
x = cursor.getInt(index);
// now x is either null or contains a valid value