Skip site navigation (1) Skip section navigation (2)

Re: java.sql.date insert as null

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: Mican Bican <mican58(at)gmail(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: java.sql.date insert as null
Date: 2005-03-07 20:04:39
Message-ID: 422CB3D7.50000@opencloud.com (view raw or flat)
Thread:
Lists: pgsql-jdbc
Mican Bican wrote:

> How can I store a java.sql.date as null in database. The problem is 
> (pseudecode):

Real test code would be much better.

> ..insert into Customer (id..,date,...)
> values(...
> ...." ' "+in.getSqlDate()+" ' ".....
> ...)

If in.getSqlDate() returns null, this turns into:

   insert into Customer (...) values (... 'null' ...)

which is wrong -- the NULL should be unquoted.

I'd suggest using a java.sql.PreparedStatement and parameter 
placeholders, then you don't need to worry about the details of "how do 
I represent a date in the right format for this DB?"

-O

In response to

pgsql-jdbc by date

Next:From: Oliver JowettDate: 2005-03-07 20:06:37
Subject: Re: postgre 7.3 / JSTL problem
Previous:From: Mican BicanDate: 2005-03-07 20:01:26
Subject: Convert java.sql.Date to java.util.Date

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group