I am executing a Statement query and storing the data in ResultSet rs.
// if no record is returned by the query
if (!rs.next() ) {
Step1
}
// if atleast one record is returned by the query
if(rs.next()){
do {
if (rs.getString(1).equalsIgnoreCase("0")){
Step2
}
if (rs.getString(1).equalsIgnoreCase("1")){
Step3
}
} while (rs.next());
}
However if i am getting only a single record from the query then no steps are executed. It would be of great help if anyone can point out the mistake.
You are always skipping first element because you are calling .next()
twice before taking an element.
Try doing something like this:
if (rs.next()) {
// At least one record returned
do {
if (rs.getString(1).equalsIgnoreCase("0")) {
// Step2
}
if (rs.getString(1).equalsIgnoreCase("1")) {
// Step3
}
} while (rs.next());
} else {
// No records returned
}