Table A
id | salary | company
1 | 500 | 2
2 | 700 | 2
3 | 900 | 3
4 | 1100 | 4
5 | 600 | 5
I want to insert MySQL into a java array. However, my current query is only bringing in the last result of the MySQL table into my database.id[I] array, and then repopulating that same result from I=0 to I=10 for the entire array. Sorry for the abbreviated code, but it is working, just not the way I would like it to.
Ideally, I would like for my database.id[I] array to only bring in from table A id[1] and id[2] as that is where company = 2. Thank you for any assistance!
Statement stmt = conn.createStatement();
String query = String.format("select * from table A where company =2");
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
for (int i = 0; i < 10; ++i) {
database.id[i] = rs.getInt("id");
database.salary[i] = rs.getInt("salary");
}}
id