jQuery in Action, 2nd edition*
The moose likes JDBC and the fly likes Need a conditional Statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Need a conditional Statement" Watch "Need a conditional Statement" New topic

Need a conditional Statement

Faisal Fuad
Ranch Hand

Joined: Jul 05, 2011
Posts: 79

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

Joined: Jul 05, 2011
Posts: 79

.......And i got the solution. Just added .....so funny ;)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Faisal Fuad
Ranch Hand

Joined: Jul 05, 2011
Posts: 79

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
I agree. Here's the link: http://aspose.com/file-tools
subject: Need a conditional Statement
Similar Threads
page refresh problem
vector problem,how to retrieve data stored in vector and display in jsp pag
Paging in jsp
retrieving column caption in access
Menu Component