pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
PreparedStatement.setString with null
3+ messages / 3 participants
[nested] [flat]

* PreparedStatement.setString with null
@ 2004-09-30 09:55  Tim Penhey <tim@penhey.net>
  0 siblings, 2 replies; 3+ messages in thread

From: Tim Penhey @ 2004-09-30 09:55 UTC (permalink / raw)
  To: pgsql-jdbc

What is this supposed to do?

    PreparedStatement stat = connection.prepareStatement("update table1 
set col1 = ?");
    stat.setString(1, null);

Will this make a null value in the database or an empty string?  Do we 
have to use the setNull(1, Types.VARCHAR) in order to get a null value 
entered?

Thanks,
Tim




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

* Re: PreparedStatement.setString with null
@ 2004-09-30 10:13  Roland Walter <rwa@mosaic-ag.com>
  parent: Tim Penhey <tim@penhey.net>
  1 sibling, 0 replies; 3+ messages in thread

From: Roland Walter @ 2004-09-30 10:13 UTC (permalink / raw)
  To: Tim Penhey <tim@penhey.net>; +Cc: pgsql-jdbc

Tim Penhey schrieb:

> What is this supposed to do?
>
>    PreparedStatement stat = connection.prepareStatement("update table1 
> set col1 = ?");
>    stat.setString(1, null);
>
> Will this make a null value in the database or an empty string?  Do we 
> have to use the setNull(1, Types.VARCHAR) in order to get a null value 
> entered?

If you want to be portable to different databases, use the setNull() method.

-- 
Roland Walter
MOSAIC SOFTWARE AG
Telefon: 02225/882-411 Fax: 02225/882-201
http://www.mosaic-ag.com




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

* Re: PreparedStatement.setString with null
@ 2004-09-30 10:34  Oliver Jowett <oliver@opencloud.com>
  parent: Tim Penhey <tim@penhey.net>
  1 sibling, 0 replies; 3+ messages in thread

From: Oliver Jowett @ 2004-09-30 10:34 UTC (permalink / raw)
  To: Tim Penhey <tim@penhey.net>; +Cc: pgsql-jdbc

Tim Penhey wrote:
> What is this supposed to do?
> 
>    PreparedStatement stat = connection.prepareStatement("update table1 
> set col1 = ?");
>    stat.setString(1, null);
> 
> Will this make a null value in the database or an empty string?  Do we 
> have to use the setNull(1, Types.VARCHAR) in order to get a null value 
> entered?

The postgresql JDBC driver treats setString(x, null) identically to 
setNull(x, Types.VARCHAR). I don't know how portable this behaviour is; 
the javadoc is silent on how this case should be handled. You're 
probably better off using setNull() explicitly.

-O



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


end of thread, other threads:[~2004-09-30 10:34 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-09-30 09:55 PreparedStatement.setString with null Tim Penhey <tim@penhey.net>
2004-09-30 10:13 ` Roland Walter <rwa@mosaic-ag.com>
2004-09-30 10:34 ` 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