2

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

Oleg Mikheev
  • 17,186
  • 14
  • 73
  • 95
vkumar
  • 21
  • 1
  • 1
  • 3
  • "*i need to provide SQL type of the target column, which doesn't seem possible*". Why? Don't you know the definition of your table? (Btw: there is no `SetObject()` function in JDBC, only `setObject()`) –  Mar 22 '13 at 23:25

2 Answers2

5

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!

Oleg Mikheev
  • 17,186
  • 14
  • 73
  • 95
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

Abhinav
  • 2,085
  • 1
  • 18
  • 31