This discussion is archived
3 Replies Latest reply: Oct 24, 2013 12:42 PM by Subramanian Meyyappan RSS

How to create the datacontrol for a table using POJO.

9687ddef-1daf-48e9-be80-325257366065 Newbie
Currently Being Moderated

Hi,

 

Can you guys tell me the procedure to create the datacontrol thing using  pojo so that we can use that in jsf page for displaying the content just like BC.

I have little knowledge about adf and I just want to clear my concept.

 

Thanks in advance,

Harsh

  • 2. Re: How to create the datacontrol for a table using POJO.
    Shay Shmeltzer Employee ACE
    Currently Being Moderated

    Have a class that represent your object for example Emp that has several attributes.

    Then have a class that has a Collection<Emp> with a getter method.

    Right click the second class and choose create data control.

  • 3. Re: How to create the datacontrol for a table using POJO.
    Subramanian Meyyappan Expert
    Currently Being Moderated

    sounds like this.

    import java.sql.Connection;

    import java.sql.Date;

    import java.sql.PreparedStatement;

    import java.sql.ResultSet;

    import java.sql.SQLException;

    import java.util.ArrayList;

    import java.util.List;

    import oracle.sql.NUMBER;

     

    public class Employees {

     

        public Employees() {

         ............

       }

        public Number EMPLOYEE_ID;

        public String FIRST_NAME;

        public String LAST_NAME;

        public String EMAIL;

        public String PHONE_NUMBER;

        public Date HIRE_DATE;

        public String JOB_ID;

        public Number SALARY;

        public Number COMMISSION_PCT;

        public Number MANAGER_ID;

        public Number DEPARTMENT_ID;

     

     

        ArrayList<Employees> empdata = new ArrayList<Employees>();

     

     

        public Employees(Number EMPLOYEE_ID, String FIRST_NAME, String LAST_NAME,

                         String EMAIL, String PHONE_NUMBER, Date HIRE_DATE,

                         String JOB_ID, Number SALARY, Number COMMISSION_PCT,

                         Number MANAGER_ID, Number DEPARTMENT_ID) {

            this.EMPLOYEE_ID = EMPLOYEE_ID;

            this.FIRST_NAME = FIRST_NAME;

            this.LAST_NAME = LAST_NAME;

            this.EMAIL = EMAIL;

            this.PHONE_NUMBER = PHONE_NUMBER;

            this.HIRE_DATE = HIRE_DATE;

            this.JOB_ID = JOB_ID;

            this.SALARY = SALARY;

            this.COMMISSION_PCT = COMMISSION_PCT;

            this.MANAGER_ID = MANAGER_ID;

            this.DEPARTMENT_ID = DEPARTMENT_ID;

        }

     

     

        private ArrayList<Employees> selectRecordsFromTable(Integer did) throws SQLException {

     

     

            Connection dbConnection = null;

            PreparedStatement preparedStatement = null;

     

     

            String selectSQL =

                "select " + "EMPLOYEE_ID , " + "FIRST_NAME , " + "LAST_NAME, " +

                "EMAIL, " + "PHONE_NUMBER, " + "HIRE_DATE, " + "JOB_ID, " +

                "SALARY, " + "COMMISSION_PCT," + "MANAGER_ID, " +

                "DEPARTMENT_ID " + "from employees where department_id = ? ";

     

     

            try {

                dbConnection = new DbConnection().dbconnect();

                preparedStatement = dbConnection.prepareStatement(selectSQL);

                preparedStatement.setInt(1, did);

     

     

                // execute select SQL stetement

                ResultSet rs = preparedStatement.executeQuery();

     

     

                while (rs.next()) {

                                    Number val1 = Integer.valueOf(rs.getString(1));

                                    String val2 = rs.getString(2);

                                    String val3 = rs.getString(3);

                                    String val4 = rs.getString(4);

                                    String val5 = rs.getString(5);

                                    Date val6 = rs.getDate(6);

                                    String val7 = rs.getString(7);

                                    Number val8 = Integer.valueOf(rs.getString(8));

                                    Number val9 = Integer.valueOf(rs.getString(9));

                                    Number val10 = Integer.valueOf(rs.getString(10));

                                    Number val11 = Integer.valueOf(rs.getString(11));

                                    empdata.add(new Employees(val1, val2, val3, val4, val5, val6, val7, val8,

                                                  val9, val10, val11));

     

     

     

     

                }

     

     

     

     

            } catch (SQLException e) {

     

     

                System.out.println("error" + e.getMessage());

     

     

            } finally {

     

     

                if (preparedStatement != null) {

                    preparedStatement.close();

                }

     

     

                if (dbConnection != null) {

                    dbConnection.close();

                }

     

     

            }

            return empdata;

        }

     

     

        public void setEMPLOYEE_ID(Number EMPLOYEE_ID) {

            this.EMPLOYEE_ID = EMPLOYEE_ID;

        }

     

     

        public Number getEMPLOYEE_ID() {

            return EMPLOYEE_ID;

        }

     

     

        public void setFIRST_NAME(String FIRST_NAME) {

            this.FIRST_NAME = FIRST_NAME;

        }

     

     

        public String getFIRST_NAME() {

            return FIRST_NAME;

        }

     

     

        public void setLAST_NAME(String LAST_NAME) {

            this.LAST_NAME = LAST_NAME;

        }

     

     

        public String getLAST_NAME() {

            return LAST_NAME;

        }

     

     

        public void setEMAIL(String EMAIL) {

            this.EMAIL = EMAIL;

        }

     

     

        public String getEMAIL() {

            return EMAIL;

        }

     

     

        public void setPHONE_NUMBER(String PHONE_NUMBER) {

            this.PHONE_NUMBER = PHONE_NUMBER;

        }

     

     

        public String getPHONE_NUMBER() {

            return PHONE_NUMBER;

        }

     

     

        public void setHIRE_DATE(Date HIRE_DATE) {

            this.HIRE_DATE = HIRE_DATE;

        }

     

     

        public Date getHIRE_DATE() {

            return HIRE_DATE;

        }

     

     

        public void setJOB_ID(String JOB_ID) {

            this.JOB_ID = JOB_ID;

        }

     

     

        public String getJOB_ID() {

            return JOB_ID;

        }

     

     

        public void setSALARY(Number SALARY) {

            this.SALARY = SALARY;

        }

     

     

        public Number getSALARY() {

            return SALARY;

        }

     

     

        public void setCOMMISSION_PCT(Number COMMISSION_PCT) {

            this.COMMISSION_PCT = COMMISSION_PCT;

        }

     

     

        public Number getCOMMISSION_PCT() {

            return COMMISSION_PCT;

        }

     

     

        public void setMANAGER_ID(Number MANAGER_ID) {

            this.MANAGER_ID = MANAGER_ID;

        }

     

     

        public Number getMANAGER_ID() {

            return MANAGER_ID;

        }

     

     

        public void setDEPARTMENT_ID(Number DEPARTMENT_ID) {

            this.DEPARTMENT_ID = DEPARTMENT_ID;

        }

     

     

        public Number getDEPARTMENT_ID() {

            return DEPARTMENT_ID;

        }

     

     

        public void setEmpdata(ArrayList<Employees> empdata) {

            this.empdata = empdata;

        }

     

     

        public ArrayList<Employees> getEmpdata() {

            return empdata;

        }

    }

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points