Re: timestamp parameter is null

From: Markus Schaber <schabi(at)logix-tt(dot)com>
To: Papp Márton <papp(dot)marton(at)assixo(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: timestamp parameter is null
Date: 2006-02-01 17:15:25
Message-ID: 43E0ECAD.3060609@logix-tt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kris Jurka 2006-02-01 17:23:32 Re: getTablePrivillages giving wrong privillages
Previous Message Roland Walter 2006-02-01 16:51:25 Re: timestamp parameter is null