Reputation: 6426
What is the difference between the following statements.
PreparedStatement.setNull(1, java.sql.Types.NULL);
and
PreparedStatement.setNull(1, java.sql.Types.INTEGER);
Upvotes: 3
Views: 862
Reputation: 109046
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.
Upvotes: 1