Java : Passing null as Long in PreparedStatement (JDBC)
java, jdbc
Solution
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.
Problem
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 !!!