pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: rob stone <floriparob@gmail.com>
To: Rémi Aubel <remi.aubel@gmail.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: "could not determine data type of parameter" with timestamp
Date: Wed, 06 Dec 2017 07:22:15 +1100
Message-ID: <1512505335.4814.5.camel@gmail.com> (raw)
In-Reply-To: <CAG2M1febgZbhBwm0DQK4Y5ekDrTbzTyAa1syKcdXw+6Y8caK4g@mail.gmail.com>
References: <CAG2M1febgZbhBwm0DQK4Y5ekDrTbzTyAa1syKcdXw+6Y8caK4g@mail.gmail.com>



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 




view thread (29+ messages)  latest in thread

Message-ID: <1512505335.4814.5.camel@gmail.com>
Permalink:  ../1512505335.4814.5.camel@gmail.com/
Also on:    postgresql.org/message-id/1512505335.4814.5.camel@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: floriparob@gmail.com, remi.aubel@gmail.com
  Subject: Re: "could not determine data type of parameter" with timestamp
  In-Reply-To: <1512505335.4814.5.camel@gmail.com>
  References: <CAG2M1febgZbhBwm0DQK4Y5ekDrTbzTyAa1syKcdXw+6Y8caK4g@mail.gmail.com> <1512505335.4814.5.camel@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox