Public void insertPressed(View view) {



Download 103.36 Kb.
Page3/3
Date11.05.2021
Size103.36 Kb.
#56601
1   2   3
MOBILEDEV
Update by ID

1/ Include a DAO function for updating:


@Update

public void updateEmployee(Employee e);

2/ Check the  employee table class and see if we have a way to instinatie new employee objects with an id



@Entity(tableName = "employees")

public class Employee {
   // database to automatically assign values

   @PrimaryKey(autoGenerate = true)

   int id;

   String name;

   String date_hired;
   // constructors

   public Employee(String name, String date_hired) {

       this.name = name;

       this.date_hired = date_hired;

   }
   // add an additional constructor that enables us to create employees with an id

   @Ignore

   public Employee(int id, String name, String date_hired) {

       this.id = id;

       this.name = name;

       this.date_hired = date_hired;

   }
   @Override

   public String toString() {

       return "Employee{" +

               "name='" + name + '\'' +

               ", date_hired='" + date_hired + '\'' +

               ", id=" + id +

               '}';

   }

}

3/ In your main activity, call the updateEmployee function


 public void updatePressed(View view) {

   Employee e1 = new Employee(99, "Peter", "");

   empDAO.updateEmployee(e1);

}
Download 103.36 Kb.

Share with your friends:
1   2   3




The database is protected by copyright ©ininet.org 2024
send message

    Main page