Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T41Js-0006le-3I for pgsql-jdbc@postgresql.org; Wed, 22 Aug 2012 03:09:24 +0000 Received: from mail-pb0-f46.google.com ([209.85.160.46]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T41Jp-0007wz-AU for pgsql-jdbc@postgresql.org; Wed, 22 Aug 2012 03:09:23 +0000 Received: by pbbrr13 with SMTP id rr13so822908pbb.19 for ; Tue, 21 Aug 2012 20:09:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:x-gm-message-state; bh=Ca3KBmwZBRlDku8LA/6YUP4kdzfnDZDcLwcmeJiXAt4=; b=lER9+GQtTxkYE7yla0RVSQnyV8us7yINfmgxd32VWAP+SOjd8NeMqGCUJSRl5dWW1/ TdX+IkH/B+sc3nEdcv1uurVUXX5iXDyiyCYDW6HrBA+5Bb99Y25vbME8lSwKa1Rft8a6 9sUS2e3JjckpChcW8DvszU1EENjLLZuBQxUJb9piqeDMD27+OMx6JC4AqIB/mMzfnj2u sEXt3CysYFVm12NgD8HOcHEO8IbPZokIDUyieABb/EeHglzJgh1iOarAELRdQXqQtF+r eNVFfM+3Xlw2HmkYlvM5mLzrRV5JTNnMLsP2N7ckcODRBzkmj8+1h3D0dD9BasLgwe90 XArg== Received: by 10.68.234.65 with SMTP id uc1mr29073876pbc.89.1345604957661; Tue, 21 Aug 2012 20:09:17 -0700 (PDT) Received: from ayaki.localdomain (office1.postnewspapers.com.au. [150.101.171.128]) by mx.google.com with ESMTPS id gf3sm2686864pbc.74.2012.08.21.20.09.14 (version=SSLv3 cipher=OTHER); Tue, 21 Aug 2012 20:09:16 -0700 (PDT) Message-ID: <50344D58.9010401@ringerc.id.au> Date: Wed, 22 Aug 2012 11:09:12 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120717 Thunderbird/14.0 MIME-Version: 1.0 To: PostgreSQL JDBC Subject: setObject(...) with native Java arrays like String[] ? Content-Type: multipart/alternative; boundary="------------010909080807080100090307" X-Gm-Message-State: ALoCoQmq/A52mcfEJuGnpiOegX8nlw5BilVMQ5N8aK0YXvTGzHQIIapkCCzHrQlmsZDlYAYRFiCS X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201208/53 X-Sequence-Number: 23208 This is a multi-part message in MIME format. --------------010909080807080100090307 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit 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 --------------010909080807080100090307 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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
--------------010909080807080100090307--