I’m fairly new to Java and I was wondering how I could get all of the columns of a returned via MySQL query. For instance,
SELECT * FROM `login`
And then I had this code to return the results:
while (rs.next()) {
for (byte i = 1; i < 10; i++) {
result = result+" "+rs.getString(i);
}
}
I want 10 in the for loop to be the maximum number of columns because of dynamic MySQL queries. Is there a simple way to do this? Thanks.
Although, as duffymo suggested, it’s better to spell out the columns you want to receive in the query, you can use ResultSet metadata to fetch the number of columns returned: