Re: Bug: Cannot pass null in Parameter in Query for ISNULL - Mailing list pgsql-jdbc

From Oliver Jowett
Subject Re: Bug: Cannot pass null in Parameter in Query for ISNULL
Date
Msg-id CA+0W9LN_HnO8AKPBTLAGWo9xfYnFXGT7BcCNBp7xBsx1y_y5-w@mail.gmail.com
Whole thread Raw
In response to Bug: Cannot pass null in Parameter in Query for ISNULL  (bht@actrix.gen.nz)
Responses Re: Bug: Cannot pass null in Parameter in Query for ISNULL
List pgsql-jdbc
On 30 November 2011 19:51,  <bht@actrix.gen.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

pgsql-jdbc by date:

Previous
From: Mikko Tiihonen
Date:
Subject: Re: Bug when retrieving money datatype.
Next
From: Oliver Jowett
Date:
Subject: Re: Bug: Cannot pass null in Parameter in Query for ISNULL