Step 2: Adding a listDepartments() Method to the Session Bean |
Previous |
Next |
Now you need to call the findByDname() method on the entity bean
by creating a new method on the session bean.
To add a new method to the session bean:
listDepartments() method and typing the following:listByDname(String dname) : String

public String listByDname(String dname)
{
try {
DeptLocal dept = getDeptLocalHome().findByDname(dname) ;
StringBuffer sb = new StringBuffer ("Department Details....\n");
sb.append(dept.getDepartment_id() + "......" +
dept.getDepartment_name() + "......" +
dept.getLocation_id() + "......\n");
return sb.toString();
}
catch(NamingException ne)
{
System.out.println(ne.toString());
throw new javax.ejb.EJBException(ne);
}
catch(FinderException fe)
{
System.out.println(fe.toString());
throw new javax.ejb.EJBException(fe);
}
}