Skip to main content

Posts

Showing posts with the label double datatype

"double" datatype doesn't accept null values

The application gets a double value from the database. Database has and allows "null" values for a double type variable but in my java code I can't assign null values to the variable type double. double var1 = null; -- this throws an error Double var2 = null; -- no error thrown here reason: double is a primitive datatype and thus can't initialize it to a null but we can assign a null to Double as it takes the input as an object which encapsulates a primitive datatype. its like a wrapper to the primitive datatype thus can be initiated to null we can read the null value into our code as double var1 = resultset.getDouble(columnIndex); if the column has null it will return a zero thus saving your variable from the null pointer exception!