pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Markus Schaber <schabi@logix-tt.com>
To: Papp Márton <papp.marton@assixo.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: timestamp parameter is null
Date: Wed, 01 Feb 2006 18:15:25 +0100
Message-ID: <43E0ECAD.3060609@logix-tt.com> (raw)
In-Reply-To: <43E0DFE1.9020200@assixo.com>
References: <43E0DFE1.9020200@assixo.com>

Hi, Papp,

Papp Márton wrote:

> I'm trying to execute a simple SQL query with JDBC and I get an
> exception, which I don't understand why. Here's the code:
> 
>    public static void main(String[] args) throws Exception {
>        Class.forName("org.postgresql.Driver");
>        Connection conn =
> DriverManager.getConnection("jdbc:postgresql://localhost:5434/dbname",
> "user", "pass");
>        PreparedStatement stm = conn.prepareStatement("select * from
> tablename where ? is not null");
>        stm.setTimestamp(1, new Timestamp(new Date().getTime()));
>        stm.executeQuery();
>    }

Are you shure that your query is correct?

This would return no rows if you set parameter 1 to null, and the whole
table if you set your parameter to anything not-null.

If you really want to do this, use "select * from tablename where
?::timestamp with time zone is not null"

hth,
schabi


-- 
Markus Schaber | Logical Tracking&Tracing International AG
Dipl. Inf.     | Software Development GIS

Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org



view thread (3+ messages)

Message-ID: <43E0ECAD.3060609@logix-tt.com>
Permalink:  ../43E0ECAD.3060609@logix-tt.com/
Also on:    postgresql.org/message-id/43E0ECAD.3060609@logix-tt.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: schabi@logix-tt.com, papp.marton@assixo.com
  Subject: Re: timestamp parameter is null
  In-Reply-To: <43E0ECAD.3060609@logix-tt.com>
  References: <43E0DFE1.9020200@assixo.com> <43E0ECAD.3060609@logix-tt.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