title: JAVA - Checking for NULL value from a result set
body: <p>I need to check if a value extracted from a result set is not NULL before using it.
  I found this solution</p>
  
  <pre><code>int value = 0;
  ResultSet rs = stmt.executeQuery(query);
  if (rs.next()) {
     value = rs.getInt("FIELD");
     if (!rs.wasNull()) {
         // use NOT NULL field value
     }
  }
  </code></pre>
  
  <p>but I need to check the field value directly, with no assignment to a variable since the data type is not known in advance.</p>
  
  <p>To explain better the goal, here my code:</p>
  
  <pre><code>Method method_one = null, methodResultSet=null;
  
  switch(field_type){
      case "int":
         method_one = clazzAbstractClass.getDeclaredMethod("setValue_INT", short[].class,String.class,int.class);
         break;
     case "float":
         method_one = clazzAbstractClass.getDeclaredMethod("setValue_FLOAT", short[].class,String.class,float.class);
         break;
     case "double":
         method_one = clazzAbstractClass.getDeclaredMethod("setValue_DOUBLE", short[].class,String.class,double.class);
         break;
  }
  
  methodResultSet = clazzResultSet.getDeclaredMethod("get"+field_type.substring(0, 1).toUpperCase() + field_type.substring(1), String.class); // e.g. rs.getInt
  
  // current call with NO CHECK on NULL                   
  method_one.invoke(my_object, methodResultSet.invoke(rs, FIELD_NAME);
  </code></pre>
  
  <p>In a few words, the code creates something like that:</p>
  
  <pre><code>my_object.setValue_INT(rs.getInt("FIELD"))
  </code></pre>
  
  <p>NB: getInt uses 0 as default value for NULL value</p>
  
  <p>My goal is to directly put either the FIELD VALUE or NULL as argument of the setValue_INT function.</p>