Reputation: 862
I have a variable which is
Long val = null;
And I am looking for a way to pass this to PreparedStatement statement object in order to set the field value in the database as null.
statement.setLong(1,val);
It does not work for Long, but only long.
Any inputs ideas, or suggestions.
Thanks !!!
Upvotes: 5
Views: 9236
Reputation: 178263
You should use the setNull
method.
statement.setNull(1, Types.BIGINT); // Types.BIGINT maps to 64-bit long
When mapping Java types to JDBC types, this article states:
The recommended Java mapping for the BIGINT type is as a Java long.
Upvotes: 19