I have a problem, which may be a design problem, but I'm struggling to find a way to overcome it.
In my sqlite database in my Android application, I have a table called Customer . This has about 40 columns of various string and int data types. In practice, any of these columns may or may not be null.
In my code, I have a function, simply called getCustomer() , which queries the database for a particular customer and puts all of their cells from the database into the Customer class, which contains the variables for each column. Then I can transfer this client object as I wish. The getCustomer() function returns this Customer object.
My problem is integers, which can be zero. I am familiar with how int cannot be null in java, but how Integer can be null. But my problem is that the cells in the database may be empty (e.g. null).
For string columns, I just do this:
Customer cust = new Customer(); cust.firstName = cursor.getString(0);
If cursor.getString(0); returns a null value, then the variable firstName to null. Nice and simple. However, using int:
Customer cust = new Customer(); cust.daysSinceJoining = cursor.getInt(5);
The above runtime crash if daysSinceJoining is NULL. So I tried the following:
Customer cust = new Customer(); if (cursor.getInt(5) != null) cust.daysSinceJoining = cursor.getInt(5);
However, this gives me a compiler error, since you cannot use int in null comparison.
How can I get around this problem? How can I get int from sqlite database when int value can be null?