Skip to content
Advertisement

How would I get multiple results from a MySQL table? [closed]

Say I have 2 columns, the first one is ID and the second one is colour.

How would I search for a specific colour and get all of the id’s that are in the same row as the colour?

How would I turn the results into an array?

I know how to do a simple string.

JavaScript

This is what it should look like

JavaScript

Advertisement

Answer

JavaScript
  • Use try-with-resources to make sure that you close the PreparedStatement and the Connection.
  • Each call to method next() (in ResultSet) will return the next row in the result set. Extract the ID from the row and add it to the ArrayList.
  • If you want an array, rather than ArrayList, you can convert ArrayList to array with one of the toArray methods in class ArrayList.

Maybe this will also help:
https://docs.oracle.com/javase/tutorial/jdbc/index.html

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement