aspose file tools*
The moose likes JDBC and the fly likes In SQL, what kind of value is NULL? How can I check if a field is NULL? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "In SQL, what kind of value is NULL? How can I check if a field is NULL?" Watch "In SQL, what kind of value is NULL? How can I check if a field is NULL?" New topic
Author

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

Tarek Khojah
Ranch Hand

Joined: Jul 21, 2007
Posts: 58
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

Joined: Apr 14, 2004
Posts: 10336

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 ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Tarek Khojah
Ranch Hand

Joined: Jul 21, 2007
Posts: 58
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

Joined: May 26, 2003
Posts: 30917
    
158

JDBC provides a method for that:



[edited to fix code tags]
[ October 20, 2007: Message edited by: Jeanne Boyarsky ]

[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
Tarek Khojah
Ranch Hand

Joined: Jul 21, 2007
Posts: 58
Ah, thank you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: In SQL, what kind of value is NULL? How can I check if a field is NULL?