pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Craig Ringer <ringerc@ringerc.id.au>
To: PostgreSQL JDBC <pgsql-jdbc@postgresql.org>
Subject: setObject(...) with native Java arrays like String[] ?
Date: Wed, 22 Aug 2012 11:09:12 +0800
Message-ID: <50344D58.9010401@ringerc.id.au> (raw)

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/12065...

--
Craig Ringer

view thread (14+ messages)  latest in thread

Message-ID: <50344D58.9010401@ringerc.id.au>
Permalink:  ../50344D58.9010401@ringerc.id.au/
Also on:    postgresql.org/message-id/50344D58.9010401@ringerc.id.au

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: ringerc@ringerc.id.au
  Subject: Re: setObject(...) with native Java arrays like String[] ?
  In-Reply-To: <50344D58.9010401@ringerc.id.au>
  References: <50344D58.9010401@ringerc.id.au>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox