File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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 funny ;)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114

Yes, but there is a bug in your code.

When you first do if ( and then you again call 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(; 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
It is sorta covered in the JavaRanch Style Guide.
subject: Need a conditional Statement