Re: Q: use setObject also for int or string - Mailing list pgsql-jdbc

From Kris Jurka
Subject Re: Q: use setObject also for int or string
Date
Msg-id Pine.BSO.4.64.0809181939380.28127@leary.csoft.net
Whole thread Raw
In response to Q: use setObject also for int or string  (Michael Enke <michael.enke@wincor-nixdorf.com>)
List 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

pgsql-jdbc by date:

Previous
From: Michael Enke
Date:
Subject: Q: use setObject also for int or string
Next
From: Kris Jurka
Date:
Subject: Re: Broken links on the mailing lists page