This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I'm having problems finding the right syntax. How would you test to see if a resultset is empty? if(result= what?) I've tried null and "" but it's not the right type. What is the correct way to do this?
Alex Kravets
Ranch Hand
Joined: Jan 24, 2001
Posts: 476
posted
0
I think you can do something like this: ResultSet ResSet = con.executeQuery(sql); boolean more = ResSet.next(); if(more){ // or while(more) ..... ..... } .....
All right brain, you don't like me and I don't like you, but let's just do this one thing so I can get back to killing you with beer.<br /> <br />- Homer Simpson
Alex Kravets
Ranch Hand
Joined: Jan 24, 2001
Posts: 476
posted
0
in previous, if(more) returns false then your ResultSet is empty.
Annette L'Heureux
Ranch Hand
Joined: Dec 07, 2000
Posts: 135
posted
0
Hey thanks Alex! That did the trick!
Ben Roy
Ranch Hand
Joined: Nov 01, 2000
Posts: 70
posted
0
Just thought I'd toss in my 2 cents and add that you can skip one of the steps. if (result.next()) { } In particular, I don't think you'd want to do this: boolean more=result.next() while(more) { } since you could very well end up in a loop. Usually you see: while(result.next()) { }
Alex Kravets
Ranch Hand
Joined: Jan 24, 2001
Posts: 476
posted
0
Ben, Why would you end up in the loop? When you say while(result.next()), you check wheather the value is true or false anyway. If you do: boolean more = result.next(); you save your self space and time so you don't have to type result.next(). Don't you agree? ------------------ Alex "Java is the answer"