Re: [INTERFACES] How to set java.sql.Date to null ?

From: Peter T Mount <peter(at)retep(dot)org(dot)uk>
To: "Kapoor, Nishikant X" <Nishikant(dot)X(dot)Kapoor(at)nspco(dot)com>
Cc: "'pgsql-interfaces(at)postgresql(dot)org'" <pgsql-interfaces(at)postgresql(dot)org>, "'pgsql-general(at)postgresql(dot)org'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: [INTERFACES] How to set java.sql.Date to null ?
Date: 1998-08-03 21:40:11
Message-ID: Pine.LNX.3.96.980803223807.1201I-100000@maidast.retep.org.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-interfaces

On Mon, 3 Aug 1998, Kapoor, Nishikant X wrote:

> Hi there
>
> I'm trying to pass a java.sql.Date parameter to a sql query using
> JDBC-PostgreSQL interface. The problem shows up when I pass a null
> java.sql.Date but as it happens in my application, the user may or may
> not
> enter the logDate.
> (It works fine if the java.sql.Date(logDate) is a valid date).
> Here is the code:
>
> PreparedStatement pstmt = null;
> try {
> pstmt = connect.prepareStatement("insert into prfs (prfNo, author,
> severity, blockFunc, probArea, status, probDesc, logDate, estCompDate,
> actCompDate, assigned, assignee,
> solution, attachment, siemensVar, reviewer) values " +
> "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" );
>
> pstmt.setString(1, prfNo);
> pstmt.setString(2, author);
> pstmt.setInt(3, severity);
> pstmt.setInt(4, blockFunc);
> pstmt.setInt(5, probArea);
> pstmt.setInt(6, status);
> pstmt.setString(7, probDesc);
> --> pstmt.setDate(8, logDate); <-- NullPointerException ex
> } catch (SQLException e) { }
>
>
> How do I set a Date to be a null ?

Currently the only way is to use:

if(logDate==null)
pstmt.setString(8,null);
else
pstmt.setDate(8,jobDate);

I'm adding it to my TODO list so that setDate() and others handle nulls
correctly.

--
Peter T Mount peter(at)retep(dot)org(dot)uk or petermount(at)earthling(dot)net
Main Homepage: http://www.retep.org.uk
PostgreSQL JDBC Faq: http://www.retep.org.uk/postgres

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Roland Roberts 1998-08-03 22:54:48 PostgreSQL catalogues: finding the primary key
Previous Message Chris Johnson 1998-08-03 21:06:46 Replication information

Browse pgsql-interfaces by date

  From Date Subject
Next Message The Hermit Hacker 1998-08-04 02:07:18 Re: searching for a sql replacement of the user files (fwd)
Previous Message Kapoor, Nishikant X 1998-08-03 19:16:20 How to set java.sql.Date to null ?