#multiple results for sql query
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
select * from mytable where id = 49
?
i have
try {
PreparedStatement stmt = TFI.getDatabase().getConnection().prepareStatement("SELECT id FROM season WHERE club = ?");
stmt.setString(1, club);
ResultSet resultSet = stmt.executeQuery();
ArrayList<String> players = new ArrayList<>();
while (resultSet.next()) {
players.add()
}
resultSet.close();
stmt.close();
} catch (SQLException e) {
throw new RuntimeException(e);
}``` rn just confused on how to get the id from the while loop
Detected code, here are some useful tools:
sorry kinda worded it a bit wrong but i want to get the id of everyone who is in a certain club
Then get the id from the resultset ie resultSet.getInt(1)
but if the table was
482 club1
443 club2
399 club1
and i did something like
while (resultSet.next()) {
i++;
int id = resultSet.getInt(i);
}```
it wouldnt get the 2nd club1 though right? because the person with id 443 isnt including in the result set so it would be ignored and i wouldnt increase so when it got to the 2nd club1 i would be at 2 not 3
Detected code, here are some useful tools:
It's getInt(1)
and that would always get the newest result?
yea?
.
It's the index of the column that you pass
im testing it rn but i dont think its what i need to do
yeah but this
it wouldnt get the 2nd club1 though right? because the person with id 443 isnt including in the result set so it would be ignored and i wouldnt increase so when it got to the 2nd club1 i would be at 2 not 3
So 1 is the first column of the result
but if it was constantly 1 it would just return 1 id no?
oh nvm it seems to work ig
tysm
No
Let's say you select name, id
1 would return the name
2 would return the id
It's the index of the column
Also note that you can use the name of the column instead of the index
Ie getInt("id")
@main shadow
👍
And also
What makes it change line is the next() method
Each time you call next(), it will go to the next row
@main shadow
yeah that makes much more sense now
Closed the thread due to inactivity.
If your question was not resolved yet, feel free to just post a message to reopen it, or create a new thread. But try to improve the quality of your question to make it easier to help you 👍
how we can implement form-data upload in graphql in spring boot
please open a new post for a new question, thanks!