#multiple results for sql query

1 messages · Page 1 of 1 (latest)

main shadow
#

if i have a table where multiple people have the id "49" for example, how would i get all people with that id?

boreal citrusBOT
#

<@&987246399047479336> please have a look, thanks.

boreal citrusBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

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.

livid yacht
main shadow
# livid yacht 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
boreal citrusBOT
main shadow
#

sorry kinda worded it a bit wrong but i want to get the id of everyone who is in a certain club

livid yacht
main shadow
#

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
boreal citrusBOT
main shadow
livid yacht
#

It's similar to the previous setString but it's the reverse

#

@main shadow

main shadow
#

yea?

livid yacht
#

It's the index of the column that you pass

main shadow
#

im testing it rn but i dont think its what i need to do

main shadow
#

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

livid yacht
#

So 1 is the first column of the result

main shadow
#

but if it was constantly 1 it would just return 1 id no?

#

oh nvm it seems to work ig

#

tysm

livid yacht
#

Let's say you select name, id

#

1 would return the name
2 would return the id

#

It's the index of the column

main shadow
#

ohhhhh

#

ok that makes more sense ty

livid yacht
#

Also note that you can use the name of the column instead of the index

#

Ie getInt("id")

#

@main shadow

main shadow
#

👍

livid yacht
#

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

main shadow
#

yeah that makes much more sense now

boreal citrusBOT
#

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 👍

uncut lava
#

how we can implement form-data upload in graphql in spring boot

solar lily