I'm working on a project where I would need to write a program to take in data from MySql into a java program then save that data into an object to be used later. I already managed to set up the JDBC connection to the MySql database and get all the information from the database as well as being able to write queries to the DB. What I want to do now is store that information into an object. So, I created a table called people with the columns name and age that contain information. In my program, I have a people class with the name and age fields shown below
public class People {
private String name;
private int age;
public people(String name, int age) {
this.name = name;
this.age =age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "people{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
}
I'm wondering how I could take the MySQL data that I imported and using this people class create objects from it?
SELECTPreparedStatement(orStatement), iterating over theResultSetand constructingPeopleobjects for each row in the result set?