| Author |
PreparedStatement and 'null' value in WHERE clause
|
Radoslaw Sztando
Ranch Hand
Joined: Mar 11, 2004
Posts: 40
|
|
Hi, Why above code does not update column AGE for all records which NAME is null? In normal query I would rather use "...WHERE NAME IS NULL" for this case but I want to have general solution (handling both NULL and not NULL values in WHERE clause). Guys, do you have any idea how to do it?
|
Regards,
Radek Sztando
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26184
|
|
Originally posted by Radoslaw Sztando: Why above code does not update column AGE for all records which NAME is null?
Because you aren't using "is null". Null will never match on =.
but I want to have general solution (handling both NULL and not NULL values in WHERE clause). Guys, do you have any idea how to do it?
You are on the right track with your if statement. You just need to add a bit more logic:
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Xiangning Liu
Greenhorn
Joined: Dec 20, 2005
Posts: 3
|
|
Originally posted by Jeanne Boyarsky:
In this case, it's not necessary to use PreparedStatement, why not use Statement directly?
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26184
|
|
Originally posted by Xiangning Liu: In this case, it's not necessary to use PreparedStatement, why not use Statement directly?
Because prepared statements protect you from SQL injection. I'd much rather the JDBC driver handle that than my having to write a (possibly incorrect) validator.
|
 |
Srilakshmi Vara
Ranch Hand
Joined: Jul 21, 2004
Posts: 169
|
|
In your query your are checking name = null or name = passed value in oracle name = null is different from name is null. Change your code accordingly. HTH
|
 |
 |
|
|
subject: PreparedStatement and 'null' value in WHERE clause
|
|
|