(Think this is a java problem!!!)

When I print a result set of a mysql query it doesn't print the 1st value.

I used

ResultSet rs = stmt.executeQuery("Select * from names");
while(rs.next()){

textAr.append(rs.getString("name")+"\n");

}

This prints the values from index 2.. How can i print all the values.???

thankx in advance...

How many columns does the query return?
Try:

textAr.append(rs.getString(1)+"\n");
textAr.append(rs.getString(2)+"\n");
textAr.append(rs.getString(3)+"\n");

Or

ResultSet rs = stmt.executeQuery("Select col1, col2 from names");

.....

textAr.append(rs.getString("col1")+"\n");
textAr.append(rs.getString("col2")+"\n");

My problem is... as your example.....
if my "col1" values are 1,2,3,4 for each raw.....

the result set prints 2,3,4 ...but doesn't print 1 .....
when I use,

    while(rs.next()){

                       textAr.append(rs.getString("col1")+"\n");

    }

I want to print 1,2,3,4..
Hope you got that....please help..

thanx.

I get the problem, but I find it strange that you have it. The code should work:

ResultSet rs = ......

while (rs.next()) {
  .....
}

Is it possible that you accidentally execute the rs.next before the while loop. Also are you sure that the query actually returns: 1,2,3,4 with that order?

I get the problem, but I find it strange that you have it. The code should work:

ResultSet rs = ......

while (rs.next()) {
  .....
}

Is it possible that you accidentally execute the rs.next before the while loop. Also are you sure that the query actually returns: 1,2,3,4 with that order?

MMmm..
I have

if(rs.next()){

while(rs.next()){

}
}

Then that should be the problem rite?

"if" and "while" both do the same thing. Check if what's inside the parenthesis is true or false.
So they will both give you the same result.
Meaning that if you had only the while it will work, because it would return true or false depending on if there will be a "next" row

Move ur cursor to very first point of ur result set....

<resultset name>.beforeFirst();

It works for me....
Have fun!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.