Testing the MyBatis Application
package com.jtechies.mybatis;
import java.util.List;
import com.jtechies.mybatis.dao.EmployeeDAO;
import com.jtechies.mybatis.dto.Employee;
public class TestMyBatis
{
public static void main(String[] args)
{
// Fetch all Records
EmployeeDAO employeeDAO =
new EmployeeDAO();
List<Employee> empList =
employeeDAO.getAllEmployees();
System.out.println("Now Get All Employees ");
System.out.println(empList);
// Fetch by Empid
empList = employeeDAO.getById(1002);
System.out.println("Now Get By Id Only");
System.out.println(empList);
// Fetch By Name and Id Both
Employee emp = new Employee();
emp.setEmpid(1001);
emp.setName("Amit jtechies");
empList = employeeDAO.getByIdAndName(emp);
System.out.println
("Now GetById And Name is ");
System.out.println(empList);
// Insert a New Employee
emp = new Employee();
emp.setEmpid(1003);
emp.setName("Shyam Kumar");
emp.setDesignation("Software Enginner");
emp.setEmail("shyam@tkhts.com");
emp.setPhone("1221");
emp.setSalary(22222.33);
employeeDAO.insert(emp);
System.out.println("Record Added....");
employeeDAO = new EmployeeDAO();
empList = employeeDAO.getAllEmployees();
System.out.println
("Now Get All Employees After Add ");
System.out.println(empList);
// Delete an Existing Record
employeeDAO.delete(1001);
System.out.println("Record Deleted....");
employeeDAO = new EmployeeDAO();
empList = employeeDAO.getAllEmployees();
System.out.println
("Now Get All Employees After Delete ");
System.out.println(empList);
// Update an Existing Record
emp = new Employee();
emp.setEmpid(1003);
emp.setName("Shyam Kumar");
emp.setDesignation("SSE");
employeeDAO.update(emp);
employeeDAO = new EmployeeDAO();
empList = employeeDAO.getAllEmployees();
System.out.println
("Now Get All Employees After Updation ");
System.out.println(empList);
}
}



