From: | Rémi Aubel <remi(dot)aubel(at)gmail(dot)com> |
---|---|
To: | rob stone <floriparob(at)gmail(dot)com> |
Cc: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Re: "could not determine data type of parameter" with timestamp |
Date: | 2017-12-05 20:33:51 |
Message-ID: | CAG2M1fc_1R7Y+0_utULv+9+8tZPhe3K1kxsBkyqSiV76YJjTew@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
Hi Rob,
Thank you for your answer.
Unfortunately, in my application, the condition in the where clause does
not involve a column, but the bound parameter itself (? is null). Such a
condition may be strange but, as I said previously, the request is
dynamically generated.
I guess that getMetaData() won't help here.
Rémi.
Le mar. 5 déc. 2017 à 21:22, rob stone <floriparob(at)gmail(dot)com> a écrit :
>
>
> On Tue, 2017-12-05 at 15:11 +0000, Rémi Aubel wrote:
> > Hello,
> >
> >
> >
> > The solution given 4 years ago was to explicitly cast the parameter
> > as a timestamp (select * from my_table where ?::timestamp is null).
> > But this workaround is not really useful for me, because my
> > application uses generated (dynamic) queries and targets multiple
> > database types (not only PosgreSQL). So, when I know the targeted
> > database, I do not know my parameter types anymore.
> >
> > Any suggestion?
> >
> > Thanks in advance.
> >
> > Rémi.
> >
> >
>
> Hi Rémi,
>
> After creating the Prepared Statement you can do a
> ResultSetMetaData.getMetaData() which returns an object containing the
> data types of the columns in your select list.
> Then for each column in your "where" clause you can obtain its data
> type and then do setLong, setString, setTimeStamp or whatever,
> according to its type. Then do the "execute" to obtain the actual
> result set.
>
> HTH,
> Rob
>
--
From | Date | Subject | |
---|---|---|---|
Next Message | David G. Johnston | 2017-12-05 20:42:54 | Re: "could not determine data type of parameter" with timestamp |
Previous Message | rob stone | 2017-12-05 20:22:15 | Re: "could not determine data type of parameter" with timestamp |