Java Bean Class – EmployeeBean

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class EmployeeBean {
	private String Name;
	private int EmpNo;
	private int Age;
	private float Weight;
	
	public String getName() {
		return Name;
	}
	public void setName(String name) {
		Name = name;
	}
	public int getEmpNo() {
		return EmpNo;
	}
	public void setEmpNo(int empNo) {
		EmpNo = empNo;
	}
	public int getAge() {
		return Age;
	}
	public void setAge(int age) {
		Age = age;
	}
	public float getWeight() {
		return Weight;
	}
	public void setWeight(float weight) {
		Weight = weight;
	}
	
	
	
	public EmployeeStringBean getStringBean() {
		
		EmployeeStringBean objEmpBean = new EmployeeStringBean();
		
		objEmpBean.setName(getName() == null?null:getName().toString());
		objEmpBean.setEmpNo(Integer.toString(getEmpNo()));
		objEmpBean.setAge(Integer.toString(getAge()));		
		objEmpBean.setWeight(getWeight()+"");
		
		return objEmpBean;
	}
	
	
	public static List getStringBeanList(List beanList) {
		 List stringBeanList = new ArrayList();

	        if (beanList != null) {
	            Iterator itr = beanList.iterator();

	            while (itr.hasNext()) {
	            	EmployeeBean bean = (EmployeeBean) itr.next();
	                stringBeanList.add(bean.getStringBean());
	            }
	        }

	        return stringBeanList;
	}
}

String Bean Class – EmployeeStringBean

public class EmployeeStringBean {
	private String Name;
	private String EmpNo;
	private String Age;
	private String Weight;
	
	public String getName() {
		return Name;
	}
	public void setName(String name) {
		Name = name;
	}
	public String getEmpNo() {
		return EmpNo;
	}
	public void setEmpNo(String empNo) {
		EmpNo = empNo;
	}
	public String getAge() {
		return Age;
	}
	public void setAge(String age) {
		Age = age;
	}
	public String getWeight() {
		return Weight;
	}
	public void setWeight(String weight) {
		Weight = weight;
	}	
	
	public EmployeeBean getBean()
	{
		EmployeeBean objEmployeeBean = new EmployeeBean();
		
		objEmployeeBean.setName(getName());
		objEmployeeBean.setEmpNo(Integer.parseInt(getEmpNo()));
		objEmployeeBean.setAge(Integer.parseInt(getAge()));
		objEmployeeBean.setWeight(Float.parseFloat((getWeight())));
		
		return objEmployeeBean;
	}	
}

UNION removes duplicate records (where all columns in the results are the same), UNION ALL does not.

There is a performance hit when using UNION vs UNION ALL, since the database server must do additional work to remove the duplicate rows, but usually you do not want the duplicates (especially when developing reports).

UNION Example:

 SELECT 'foo' AS bar UNION ALL SELECT 'foo' AS bar

Result

+-----+
| bar |
+-----+
| foo |
+-----+
1 row in set (0.00 sec)

UNION ALL example:

 SELECT 'foo' AS bar UNION ALL SELECT 'foo' AS bar

Result

+-----+
| bar |
+-----+
| foo |
| foo |
+-----+
2 rows in set (0.00 sec)
Posted in SQL.