Re: Q: use setObject also for int or string

From: Kris Jurka <books(at)ejurka(dot)com>
To: Michael Enke <michael(dot)enke(at)wincor-nixdorf(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Q: use setObject also for int or string
Date: 2008-09-18 23:43:45
Message-ID: Pine.BSO.4.64.0809181939380.28127@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On Thu, 18 Sep 2008, Michael Enke wrote:

> in my application, queries with placeholder are created in a generic way
> without knowing if the column is string or integer. It uses setString(1,
> "1") even on int columns.
>
> In the thread "macaddr data type and prepared statements" I found that I
> can use setObject(1, "1", Types.OTHER); and this works for me too.
>
> My question is if this is the "correct" way to continue (I can exchange
> all the setString with setObject but I can not find out the datatype of
> the columns in an easy way) or if this has drawbacks I do not see at the
> moment.

If you never have any type information, you can avoid changing all your
setString calls by setting the connection URL property
stringtype=unspecified [1]. setObject(..., Types.OTHER) is more useful
when you have some type information.

[1] http://jdbc.postgresql.org/documentation/83/connect.html#connection-parameters

Kris Jurka

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kris Jurka 2008-09-18 23:53:36 Re: Broken links on the mailing lists page
Previous Message Warren Bell 2008-09-18 19:35:11 Re: Bad Timestamp Format at 23 in 2008-09-16 18:41:00.479