Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need a conditional Statement

 
Faisal Fuad
Ranch Hand
Posts: 83
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi...another stupid problem i am facing here. Please help...

In my servlet the DB2 Connection is perfectly working, the SQL statement is also nice. I just want to implement a condision in such way so that: if (any condition comes true) then it will print the table column as well as table data, or else it will say "Table name: No record found". My problem is the condition. I was thinking many ways but everytime getting error.

Please look at the code i wrote and please help me to get the logic so that i can implement the above concept. Thank you very much

 
Faisal Fuad
Ranch Hand
Posts: 83
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.......And i got the solution. Just added .....so funny ;)
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15214
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, but there is a bug in your code.

When you first do if (rs.next()) and then you again call rs.next() in the while loop, you will have advanced the resultset two times before you get the first record, so that the first record will not appear in your table. You should make the loop a do { ... } while(rs.next()); loop to prevent this.
 
Faisal Fuad
Ranch Hand
Posts: 83
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You know Jesper, just after i posted my solution, i was victimized with that "do {...} while ()" bug Immediately. You saved me from there....Thank you soo much
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic