Skip to main content
deleted 98 characters in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Getting list from oraclean Oracle database and storing it in an object

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;
}

Getting list from oracle database and storing it in an object

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 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;
}

Getting list from an Oracle database and storing it in an object

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? Could you please suggest if it is good enough?

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;
}
edited tags
Link
200_success
  • 145.6k
  • 22
  • 190
  • 479
deleted 75 characters in body; edited tags; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Get Getting list from oracle database and storestoring it in an object

I have two admin groups - VCS, and VPN. For each group, I need to get the list of all the people in that group, andalong with their idsIDs. 

What is the best way to do this? I have the below code as of now. Could you please suggest if it is good enough? Please go easy on downvotes/comments, as I am a beginner in Java. Thanks in advance for taking the time to read my post!

Also, please let me know if I should insteadI use a map to store the data instead of creating a new object GetAdminInfoGetAdminInfo?

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;
}

Get list from oracle database and store it in an object

I have two admin groups - VCS, and VPN. For each group, I need to get list of all the people in that group, and their ids. What is the best way to do this? I have the below code as of now. Could you please suggest if it is good enough? Please go easy on downvotes/comments, as I am a beginner in Java. Thanks in advance for taking the time to read my post!

Also, please let me know if I should instead 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;
}

Getting list from oracle database and storing it in an object

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 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;
}
Source Link
Loading