According to this question/answer, this code:
try(PreparedStatement p_stmt = connection.prepareStatement(sql)) {
p_stmt.setString(1, null);
...
}
is equivalent to:
try(PreparedStatement p_stmt = connection.prepareStatement(sql)) {
p_stmt.setNull(1, java.sql.Types.VARCHAR);
...
}
My question is, is this the same with int
/ Integer
?? In other words, what would this code do:
try(PreparedStatement p_stmt = connection.prepareStatement(sql)) {
Integer i = null;
p_stmt.setInt(1, i);
...
}
setInt()
takes in a primitive int
which cannot be null, but the unboxed Integer
can be null.