Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / February 2005

Tip: Looking for answers? Try searching our database.

ResultSet has a null value...

Thread view: 
leni - 10 Feb 2005 09:37 GMT
Hello, I need your help, please...

I have a following code in my application:
PreparedStatement pstmt = con.prepareStatement(
         "SELECT * FROM USERS WHERE LOGIN = ?");
       pstmt.setRef(1, login);
       ResultSet rs2 = pstmt.executeQuery();
I want to get all rows from the table MEETINGS for certain user whos
got an unique login. But for some users (logins) there are no meetings
(no rows) in the table, so in this case ResultSet should give a "null"
value in return.
My question is how to check if ResultSet has null value?

Thank you in advance,

Paulina
Daniel Dittmar - 10 Feb 2005 10:58 GMT
> I have a following code in my application:
> PreparedStatement pstmt = con.prepareStatement(
[quoted text clipped - 6 lines]
> value in return.
> My question is how to check if ResultSet has null value?

I'm not quite sure that I understand what you want. I'm assuming you
have tables USERS and MEETINGS that can be joined through a column LOGIN:

select USERS.LOGIN, MEETINGS.MEETINGID from USERS left outer join
MEETINGS on USERS.LOGIN = MEETINGS.LOGIN
where USERS.LOGIN = ?

The syntax for the left outer join could be different for your database.

If there are no entries in MEETINGS for a specific user, you will
receive a single row containing the username and a NULL value for the
MEETINGID.

Hint: USERS.LOGIN is not necessary in the output list as you specify
that user in the where condition. But if you test the statement in some
query tool, it is quite useful if you make changes to the where condition.

Daniel
dar7yl - 11 Feb 2005 02:53 GMT
> Hello, I need your help, please...
>
[quoted text clipped - 8 lines]
> value in return.
> My question is how to check if ResultSet has null value?

I don't think you have to worry about a null value being
returned from executeQuery().  If it does, that means that
something drastic has happened, and the exception
mechanism should take care of it.

Perhaps you meant to ask:
     "Does the ResultSet return a NULL SET,
       and how do I test for it?"

The simplest way is to use one of the ResultSet accessor functions
 ( see http://java.sun.com/j2se/1.4.2/docs/api/index.html )
such as first() which returns a boolean
   true if the cursor is on a valid row;
    false if there are no rows in the result set

The conventional method for traversing the resultset
automatically takes care of the null set condition:
<code>
   while ( rs.next() )
   {
       // do something
   }
</code>

regards,
   Dar7yl


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.