setObject(...) with native Java arrays like String[] ?

Поиск
Список
Период
Сортировка
Hi all

I was recently surprised to find that PgJDBC doesn't accept Java arrays as parameters to prepared statements.

For example:

    PreparedStatement.setObject(1, new String[]{"a"}).

will fail with:

[ERROR] Internal Exception: org.postgresql.util.PSQLException: Can't infer a SQL
type to use for an instance of [Ljava.lang.String;.
Use setObject () with an explicit Types value to specify the type to use.

... which I've verified with the 902 driver in git.

After reading the spec I can't see anywhere the JDBC driver is required to accept native Java arrays, but at least EclipseLink seems to want to do it anyway. Is this reasonable to support? There's one par in the JDBC spec that suggests it might be supposed to work, but I'm not convinced it's more than bad phrasing. In §16.5.4 the JDBC4.2 draft spec reads:

    A Java array may be passed as an input parameter by calling the method
    PreparedSatement.setObject.


Thoughts? Opinions? Any idea what other DBs drivers do when they get passed a raw Java array to setObject() ?

Source:

http://stackoverflow.com/questions/12042181/how-can-i-set-a-string-parameter-to-a-native-query/12065537#12065537

--
Craig Ringer

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Scott Harrington
Дата:
Сообщение: Re: send/receive buffer size
Следующее
От: Craig Ringer
Дата:
Сообщение: Re: setObject(...) with native Java arrays like String[] ?