0
I have a problem when I put the ResultSet.next()
in the while
and get the information from the column of the Database returns me only one result.
Table 'People':
Pessoas: Idade:
Marcos 22
Marcos 24
Marcos 25
Roberto 26
Roberto 21
Code:
private static String pegarTodasAsIdades(String pessoas) {
query = "SELECT Idade FROM Pessoas WHERE Pessoas=?";
try {
ps = conn.prepareStatement(query);
ps.setString(1, pessoas);
rs = ps.executeQuery();
while (rs.next()) {
String idades = rs.getString("Idade");
return idades+"\t";
}
} catch (SQLException e) {
e.printStackTrace();
}
return "";
}
But the above code only returns me the age '19' (first of the column)
Obs:
conn = Connection
ps = PreparedStatement
rs = ResultSet
Well, if you have one
return
within thewhile
, how do you think he would return more than one result?– Victor Stafusa
Recommended reading: https://answall.com/q/172909/132
– Victor Stafusa
I modified, the post, Victor Stafusa, has no way to return inside the while? With the function being String?
– Rodrigo Oliveira