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

Поиск
Список
Период
Сортировка
От Oliver Jowett
Тема Re: Bug: Cannot pass null in Parameter in Query for ISNULL
Дата
Msg-id CA+0W9LN_HnO8AKPBTLAGWo9xfYnFXGT7BcCNBp7xBsx1y_y5-w@mail.gmail.com
обсуждение исходный текст
Ответ на Bug: Cannot pass null in Parameter in Query for ISNULL  (bht@actrix.gen.nz)
Ответы Re: Bug: Cannot pass null in Parameter in Query for ISNULL  (Oliver Jowett <oliver@opencloud.com>)
Список 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 по дате отправления:

Предыдущее
От: Mikko Tiihonen
Дата:
Сообщение: Re: Bug when retrieving money datatype.
Следующее
От: Oliver Jowett
Дата:
Сообщение: Re: Bug: Cannot pass null in Parameter in Query for ISNULL