Re: Bug: Cannot pass null in Parameter in Query for ISNULL

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: bht(at)actrix(dot)gen(dot)nz
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Bug: Cannot pass null in Parameter in Query for ISNULL
Date: 2011-11-30 07:01:52
Message-ID: CA+0W9LN_HnO8AKPBTLAGWo9xfYnFXGT7BcCNBp7xBsx1y_y5-w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On 30 November 2011 19:51, <bht(at)actrix(dot)gen(dot)nz> wrote:
> Hi,
>
> Native PostgreSQL has no problem with queries like:
>
> select id from author a where null is null or a.name = null
>
> However the JDBC driver fails to process such a query with a
> parameter:
>
> ERROR: could not determine data type of parameter $1

This is specific to calling PreparedStatement.setObject(index, null).
There is no type information provided when you call that, so it's not
entirely surprising you can get that error.
(Try a native PREPARE with a parameter type of "unknown" and you'll
see the same thing - it's not only JDBC)

To avoid this, use one of these instead:

* PreparedStatement.setObject(index, null, type)
* PreparedStatement.set<type>(index, null)
* PreparedStatement.setNull(index, type)

all of which provide type information that the driver needs.

Surely the JPA layer does know the type of the parameter it is
expecting, and so can easily call one of the variants that provides
type information?

Oliver

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Oliver Jowett 2011-11-30 07:04:43 Re: Bug: Cannot pass null in Parameter in Query for ISNULL
Previous Message Mikko Tiihonen 2011-11-30 06:55:37 Re: Bug when retrieving money datatype.