res.getInt() returns 0 for NULL?

Поиск
Список
Период
Сортировка
Искать

res.getInt() returns 0 for NULL?

От:
Jean-Christian Imbeault <jc@mega-bucks.co.jp>
Дата:
Just need a clarification. When using res.getInt() on a column with a 
null value I am getting back "0", should I not get some error thrown or 
some kind or error instead?

The following code illustrates:

int id = res.getInt("id");
if (res.wasNull()) {
   System.out.println("result was null");
}
System.out.println("id is " + id);

Output:

result was null
id is 0


Thanks,

Jc

Re: res.getInt() returns 0 for NULL?

От:
Kris Jurka <books@ejurka.com>
Дата:

This is according to the JDBC spec.  Check the API docs for getInt()

On Thu, 7 Nov 2002, Jean-Christian Imbeault wrote:

> Just need a clarification. When using res.getInt() on a column with a
> null value I am getting back "0", should I not get some error thrown or
> some kind or error instead?
>
> The following code illustrates:
>
> int id = res.getInt("id");
> if (res.wasNull()) {
>    System.out.println("result was null");
> }
> System.out.println("id is " + id);
>
> Output:
>
> result was null
> id is 0
>
>
> Thanks,
>
> Jc
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>

FAQ