pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
java.sql.date insert as null
3+ messages / 3 participants
[nested] [flat]

* java.sql.date insert as null
@ 2005-03-07 19:07 Mican Bican <mican58@gmail.com>
  2005-03-07 19:20 ` Re: java.sql.date insert as null Prasanth <dbadmin@nqadmin.com>
  2005-03-07 20:04 ` Re: java.sql.date insert as null Oliver Jowett <oliver@opencloud.com>
  0 siblings, 2 replies; 3+ messages in thread

From: Mican Bican @ 2005-03-07 19:07 UTC (permalink / raw)
  To: pgsql-jdbc

Hello,

How can I store a java.sql.date as null in database. The problem is 
(pseudecode):
....
java.sql.Date date = null;
....
Customer cust = new Customer(id);
cust.setSqlDate(date);

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

then the exception

java.sql.SQLException: ERROR: invalid input syntax for type date: "null"
........

when I select a row with empty date and system.out.print, it  gives me a 
null.. but why I can't store it as null
I use jdbc3, postgresql 8.0.1 and java 5 (tiger) on windows

thank you

best regards Mican Bican







^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: java.sql.date insert as null
  2005-03-07 19:07 java.sql.date insert as null Mican Bican <mican58@gmail.com>
@ 2005-03-07 19:20 ` Prasanth <dbadmin@nqadmin.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Prasanth @ 2005-03-07 19:20 UTC (permalink / raw)
  To: pgsql-jdbc

Remove the quotes on either side when inserting null value.

-Prasanth.

-----Original Message-----
From: pgsql-jdbc-owner@postgresql.org
[mailto:pgsql-jdbc-owner@postgresql.org]On Behalf Of Mican Bican
Sent: Monday, March 07, 2005 1:07 PM
To: pgsql-jdbc@postgresql.org
Subject: [JDBC] java.sql.date insert as null


Hello,

How can I store a java.sql.date as null in database. The problem is 
(pseudecode):
....
java.sql.Date date = null;
....
Customer cust = new Customer(id);
cust.setSqlDate(date);

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

then the exception

java.sql.SQLException: ERROR: invalid input syntax for type date: "null"
........

when I select a row with empty date and system.out.print, it  gives me a 
null.. but why I can't store it as null
I use jdbc3, postgresql 8.0.1 and java 5 (tiger) on windows

thank you

best regards Mican Bican





---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)







^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: java.sql.date insert as null
  2005-03-07 19:07 java.sql.date insert as null Mican Bican <mican58@gmail.com>
@ 2005-03-07 20:04 ` Oliver Jowett <oliver@opencloud.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Oliver Jowett @ 2005-03-07 20:04 UTC (permalink / raw)
  To: Mican Bican <mican58@gmail.com>; +Cc: 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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2005-03-07 20:04 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-03-07 19:07 java.sql.date insert as null Mican Bican <mican58@gmail.com>
2005-03-07 19:20 ` Prasanth <dbadmin@nqadmin.com>
2005-03-07 20:04 ` Oliver Jowett <oliver@opencloud.com>

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