passing null value in PreparedStatement setObject method gives exception
11,392
Solution 1
you can try using setNull with NULL type:
if(myArray == null) {
preparedStatement.setNull(i, Types.NULL);
}
And please follow Java coding standards - variables and methods are initial lower case!
Solution 2
Try:
preparedStatement.setObject(i , MyArray, java.sql.Types.ARRAY);
With the info available this is all I can come up with. Hopefully, this should work.
Abhinav
Author by
Admin
Updated on June 28, 2022Comments
-
Admin almost 2 years
Do we have a solution for this?
my code is something like this:
preparedStatement.SetObject(i , MyArray);
Here , MyArray is an array of record fetched form a table. Now , whenever the above statement finds a value null it throws an SQL exception : invalid Column type.
Options available are to use setObject(int parameterIndex, Object x, int sqlType) or setNull , but in that case i need to provide SQL type of the target column, which doesn't seem possible.
Thanks