Re: timestamp parameter is null - Mailing list pgsql-jdbc

From Markus Schaber
Subject Re: timestamp parameter is null
Date
Msg-id 43E0ECAD.3060609@logix-tt.com
Whole thread Raw
In response to timestamp parameter is null  (Papp Márton <papp.marton@assixo.com>)
List pgsql-jdbc
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

pgsql-jdbc by date:

Previous
From: Roland Walter
Date:
Subject: Re: timestamp parameter is null
Next
From: "Senden Kris"
Date:
Subject: Prepared Statement is not parsed correctly