This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes JDBC and Relational Databases 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 Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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: 83

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: 83

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

Joined: Aug 16, 2005
Posts: 14961

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 8 API documentation
Faisal Fuad
Ranch Hand

Joined: Jul 05, 2011
Posts: 83

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
Have you checked out Aspose?
subject: Need a conditional Statement
It's not a secret anymore!