Hi guys how are you?

I am having tough time extracting data from the ms database. I have three rows. WHat I want to do is the extract data from these three rows and pass to labels and display in the frame.

But I'm stuck on the first one. my program which uses rs.next() only prints the first row. That is all fine. What I want to do is put the condition after first row is displayed, like if a button is clicked then the second row should be extracted and passed to labels and displayed and so onwards.

The problem is I only know method rs.next() which is only passing the first row's values. How can I myself choose which row to printed after clicking of a button?

Guys help please!!

3 Years
Discussion Span
Last Post by llaspina

One option is to store each row as an element in a list. For instance, say the table stores Pets. Create a Java object called Pet which has data fields matching the columns in the table. This is basic the concept behind ORM (object relational matching).
Then you could do something like this:

ArrayList<Pet> petList = bew ArrayList<>();
while(rs.next() ) {
  int id = rs.getInt(0);
  String name = rs.getString(1);
  String breed = rs.getString(2);
  petList.add(new Pet(id,name,breed) );
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.