setObject(...) with native Java arrays like String[] ? - Mailing list pgsql-jdbc

From Craig Ringer
Subject setObject(...) with native Java arrays like String[] ?
Date
Msg-id 50344D58.9010401@ringerc.id.au
Whole thread Raw
Responses Re: setObject(...) with native Java arrays like String[] ?  (Craig Ringer <ringerc@ringerc.id.au>)
Re: setObject(...) with native Java arrays like String[] ?  (Craig Ringer <ringerc@ringerc.id.au>)
Re: setObject(...) with native Java arrays like String[] ?  (Craig Ringer <ringerc@ringerc.id.au>)
Re: setObject(...) with native Java arrays like String[] ?  (John Lister <john.lister@kickstone.com>)
List pgsql-jdbc
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 by date:

Previous
From: Scott Harrington
Date:
Subject: Re: send/receive buffer size
Next
From: Craig Ringer
Date:
Subject: Re: setObject(...) with native Java arrays like String[] ?