0

I guess that an integer null value within a sqlite table is not equivalent to 0 in Java. So how can I check whether the int I extract from my table with

   if(resultSet.getInt(columnNumber) != 0){
      System.out.println("int is not null");
   }

is not null? I do not want to use the sqlite constraint "IS NOT NULL".

mollwitz
  • 213
  • 3
  • 15

1 Answers1

0

It all depends what this method is doing: resultSet.getInt(...)

if getInt is returning a primitive integer, then that can not be null, but if that is an object of the class Integer then you need to check the nullabilty by doing a normal check like: resultSet.getInt(...)!= null and then after been sure that is ot null check if is not zero:

resultSet.getInt(...)!=0

Example:

if(resultSet.getInt(columnNumber) != null){
    if(resultSet.getInt(columnNumber) != 0){
        System.out.println("int is not zero");
    } else {
        System.out.println("int is zero");
    }
}else{
    System.out.println("int is null");
}
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
  • There is a common [`ResultSet`](https://docs.oracle.com/javase/8/docs/api/java/sql/ResultSet.html) interface and it is very unlikely that his implementation doesn't implements that, so `getInt` returns `int`. – Tom Mar 30 '16 at 19:10