Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

In SQL, what kind of value is NULL? How can I check if a field is NULL?

 
Tarek Khojah
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe the column holds varchar, maybe it holds int, maybe it holds whatever.

I wanted to check if a value in a given record is NULL, the column holds "long" values, what would be if statement look like? The value the column holds is "long", the column is named "MyColumn".

if (x = resultSet.getLong("MyColumn") ???)

I don't know what condition to test for exactly! Hence the question marks.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code you have written is not SQL, it looks like Java. If this is Java we are talking about, we can check is a variable == null, i.e.:


In SQL you check for null like this:


Remeber that in SQL a value is null, but may not be equal to null.
[ October 16, 2007: Message edited by: Paul Sturrock ]
 
Tarek Khojah
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remeber that in SQL a value is null, but may not be equal to null.


That was my question , let me rephrase it:

Using an if statement in the Java programming language, how can I check if a certain field in my database is null?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JDBC provides a method for that:



[edited to fix code tags]
[ October 20, 2007: Message edited by: Jeanne Boyarsky ]
 
Tarek Khojah
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, thank you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic