What is the difference between the following statements.
PreparedStatement.setNull(1, java.sql.Types.NULL);
and
PreparedStatement.setNull(1, java.sql.Types.INTEGER);
The first instructs the driver to send the null value as NULL-type, while the other as INTEGER-type. This is sometimes necessary in conditions like ? IS NULL OR someIntegerColumn = ? The first param is of a NULL-type while the second is of an INTEGER-type.
However the exact difference depends on the database driver: some databases/drivers always use the type specified by the server on prepare (and the driver converts from other types to that type), while others either require or allow to communicate in the types specified application side (the database then converts to the actual local type). This might even be necessary if the server doesn't support server side prepared statement.
There may actually be subtle implications for specifying a type: maybe one leads to a conversion error, while the other doesn't, or a subsequent conversion behaves different because of type conversions rules. I am not actually aware of this happening in practice.
NULL datatype simply means that the value is either null or not null (view it as a degenerate boolean). Some systems use it for ? IS (NOT) NULL because there is no other type to infer. The driver will not send a value to the server, just a null or not null indicator.