1

My code:

stmt.setLong(cont++, object.getLongVariable());

sometimes, longVariable will be null and i want to insert null in DB... but i get a Nullpointer! (object is not null at this point!)

so, i did a workaround:

if (object.getLongVariable() != null) {
    stmt.setLong(cont++, object.getLongVariable());
}else {
    stmt.setNull(cont++, java.sql.Types.BIGINT);
}

it works, but it sounds ugly .... there's others way to do this?

Baz
  • 36,440
  • 11
  • 68
  • 94

0 Answers0