0

I'm trying to read NULL value and 0 value from a NUMBER column from a table but for both I'm getting the value as 0.

How to read NULL value and 0 whenever needed.

Mapper.xml:

<select id="callGetDRHoldingsAdmin" parameterType="map" resultType="com.project.employee">
    SELECT 
        EMP_NUM AS empNum,
        EMP_SAL AS empSal,
        EMP_NAME AS empName
    FROM EMP_TABLE
</select>

Employee POJO

class Employee {
    private double empSal,
    private int empNum,
    private String empName
}  

EMP_TABLE:

EMP_NAME : VARCHAR2(30)
EMP_SAL  : NUMBER
EMP_NUM  : NUMBER
crazycoder
  • 65
  • 1
  • 8
  • Could it be because you are using scalar types for `empSal` and `empNum` in your `Employee` class? That is, they will default to `0.0` and `0` respectively if there's nothing assigned to them. – dave Feb 25 '19 at 01:21

1 Answers1

0

double and int are primitive types in java. The variables of these types can't hold null.

Use corresponding wrapper type which can store null:

class Employee {
    private Double empSal,
    private Integer empNum,
    private String empName
}