I have two admin groups - VCS, and VPN. For each group, I need to get the list of all the people in that group, along with their IDs.
What is the best way to do this? I have the below code as of now. Could Could you please suggest if it is good enough? Please go easy on downvotes/comments, as I am a beginner in Java.
Also, should I use a map to store the data instead of creating a new object GetAdminInfo
?
public class GetAdminInfo
{
private List<String> persons;
private List<String> personIds;
public List<String> getPersonIds() {
return personIds;
}
public void setPersonIds(List<String> personIds) {
this.personIds = personIds;
}
public List<String> getPersons() {
return persons;
}
public void setPersons(List<String> persons) {
this.persons = persons;
}
}
This is the method I have written in my DAO class.
public static GetAdminInfo fetchPersonIdInfo(String adminGroup) throws SQLException
{
GetAdminInfo personInfo =null;
Connection connection = null;
PreparedStatement statement = null;
ResultSet rs = null;
List<String> personId = new ArrayList<String>();
List<String> persons = new ArrayList<String>();
try {
connection = createConnection();
statement = connection.prepareStatement("SELECT PERSON_ID,PERSONS FROM ADMIN_INFO WHERE ADMINGROUP = ?");
statement.setString(1, adminGroup);
rs = statement.executeQuery();
if(rs.next())
{
personInfo = new GetAdminInfo();
adminGroup = rs.getString(COLUMN_ADMINGROUP)!=null?rs.getString(COLUMN_ADMINGROUP):"";
personId.add(rs.getString(1));
persons.add(rs.getString(1));
personInfo.setDeviceIds(deviceId);
personInfo.setPersonIds(personId);
}
} finally{
rs.close();
conn.close();
statement.close();
}
return personInfo;
}