📄 employeecustomerbean.java
字号:
package testejb;
//import testejb.customer;
import javax.ejb.*;
import java.util.*;
import javax.naming.*;
public class EmployeeCustomerBean implements SessionBean {
SessionContext sessionContext;
private CustomersHome customershome=null;
java.util.Vector allcustomer=new Vector();
public void ejbCreate() throws CreateException {
/**@todo Complete this method*/
try{
Context context=new InitialContext();
Object ref=context.lookup("java:/comp/env/customer");
customershome=(CustomersHome)ref;
}
catch(Exception e)
{e.printStackTrace();}
}
public void ejbRemove() {
/**@todo Complete this method*/
}
public void ejbActivate() {
/**@todo Complete this method*/
try{
Context context=new InitialContext();
Object ref=context.lookup("java:/comp/env/customer");
customershome=(CustomersHome)ref;
}
catch(Exception e)
{e.printStackTrace();}
}
public void ejbPassivate() {
/**@todo Complete this method*/
}
public void setSessionContext(SessionContext sessionContext) {
this.sessionContext = sessionContext;
}
public boolean addCustomer(String id, String name, String addr, String contact, String phone, String email, String representid) {
/**@todo Complete this method*/
try{customershome.create2(id,name,addr,contact,phone,email,representid);
return true;}
catch( Exception e)
{e.printStackTrace();
return false;}
}
public boolean deleteCustomer(String id) {
/**@todo Complete this method*/
try{
Customers customertemp = customershome.findByPrimaryKey(id);
customertemp.remove();
return true;
}catch(Exception e)
{return false;}
}
public java.util.Vector display() {
/**@todo Complete this method*/
try{Iterator i=customershome.findallcustomers().iterator();
allcustomer.clear();
while (i.hasNext()) {
Customers customertemp=(Customers)i.next();
customer tempcustomer=new customer(customertemp.getId(),customertemp.getName(),customertemp.getAddr(),customertemp.getContact(),customertemp.getPhone(),customertemp.getEmail(),customertemp.getRepresentId());
allcustomer.add(tempcustomer);
}
}catch(Exception e)
{e.printStackTrace();}
return allcustomer;
}
public testejb.customer displaysingle(String id) {
/**@todo Complete this method*/
try{
Customers customertemp = customershome.findByPrimaryKey(id);
customer tempcustomer=new customer(customertemp.getId(),customertemp.getName(),customertemp.getAddr(),customertemp.getContact(),customertemp.getPhone(),customertemp.getEmail(),customertemp.getRepresentId());
return tempcustomer;
}
catch (Exception e)
{return null;}
}
public boolean updatecustomer(String id, String name, String addr, String contact, String phone, String email, String representid) {
/**@todo Complete this method*/
try{
Customers customertemp = customershome.findByPrimaryKey(id);
customertemp.setAddr(addr);
customertemp.setContact(contact);
customertemp.setEmail(email);
customertemp.setName(name);
customertemp.setPhone(phone);
customertemp.setRepresentId(representid);
return true;
}catch(Exception e)
{return false;}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -