没有创建实体bean
我用的是weblogic,jbuilder,sql2000
bean代码如下:
Employees.java:
package cmpdemo;import javax.ejb.*;
import java.util.*;
import java.sql.*;public interface Employees extends javax.ejb.EJBLocalObject
{
public Integer getEmployeeID();
public void setLastName(String lastName);
public String getLastName();
public void setFirstName(String firstName);
public String getFirstName();
public void setTitle(String title);
public String getTitle();
public void setTitleOfCourtesy(String titleOfCourtesy);
public String getTitleOfCourtesy();
public void setBirthDate(Timestamp birthDate);
public Timestamp getBirthDate();
public void setHireDate(Timestamp hireDate);
public Timestamp getHireDate();
public void setAddress(String address);
public String getAddress();
public void setCity(String city);
public String getCity();
public void setRegion(String region);
public String getRegion();
public void setPostalCode(String postalCode);
public String getPostalCode();
public void setCountry(String country);
public String getCountry();
public void setHomePhone(String homePhone);
public String getHomePhone();
public void setExtension(String extension);
public String getExtension();
public void setPhoto(byte[] photo);
public byte[] getPhoto();
public void setNotes(String notes);
public String getNotes();
public void setReportsTo(Integer reportsTo);
public Integer getReportsTo();
public void setPhotoPath(String photoPath);
public String getPhotoPath();
}
我用的是weblogic,jbuilder,sql2000
bean代码如下:
Employees.java:
package cmpdemo;import javax.ejb.*;
import java.util.*;
import java.sql.*;public interface Employees extends javax.ejb.EJBLocalObject
{
public Integer getEmployeeID();
public void setLastName(String lastName);
public String getLastName();
public void setFirstName(String firstName);
public String getFirstName();
public void setTitle(String title);
public String getTitle();
public void setTitleOfCourtesy(String titleOfCourtesy);
public String getTitleOfCourtesy();
public void setBirthDate(Timestamp birthDate);
public Timestamp getBirthDate();
public void setHireDate(Timestamp hireDate);
public Timestamp getHireDate();
public void setAddress(String address);
public String getAddress();
public void setCity(String city);
public String getCity();
public void setRegion(String region);
public String getRegion();
public void setPostalCode(String postalCode);
public String getPostalCode();
public void setCountry(String country);
public String getCountry();
public void setHomePhone(String homePhone);
public String getHomePhone();
public void setExtension(String extension);
public String getExtension();
public void setPhoto(byte[] photo);
public byte[] getPhoto();
public void setNotes(String notes);
public String getNotes();
public void setReportsTo(Integer reportsTo);
public Integer getReportsTo();
public void setPhotoPath(String photoPath);
public String getPhotoPath();
}
package cmpdemo;import javax.ejb.*;abstract public class EmployeesBean implements EntityBean
{
EntityContext entityContext;
public java.lang.Integer ejbCreate(java.lang.Integer employeeID) throws CreateException {
setEmployeeID(employeeID);
return null;
}
public void ejbPostCreate(java.lang.Integer employeeID) throws CreateException {
/**@todo Complete this method*/
}
public void ejbRemove() throws RemoveException {
/**@todo Complete this method*/
}
public abstract void setEmployeeID(java.lang.Integer employeeID);
public abstract void setLastName(java.lang.String lastName);
public abstract void setFirstName(java.lang.String firstName);
public abstract void setTitle(java.lang.String title);
public abstract void setTitleOfCourtesy(java.lang.String titleOfCourtesy);
public abstract void setBirthDate(java.sql.Timestamp birthDate);
public abstract void setHireDate(java.sql.Timestamp hireDate);
public abstract void setAddress(java.lang.String address);
public abstract void setCity(java.lang.String city);
public abstract void setRegion(java.lang.String region);
public abstract void setPostalCode(java.lang.String postalCode);
public abstract void setCountry(java.lang.String country);
public abstract void setHomePhone(java.lang.String homePhone);
public abstract void setExtension(java.lang.String extension);
public abstract void setPhoto(byte[] photo);
public abstract void setNotes(String notes);
public abstract void setReportsTo(java.lang.Integer reportsTo);
public abstract void setPhotoPath(java.lang.String photoPath);
public abstract java.lang.Integer getEmployeeID();
public abstract java.lang.String getLastName();
public abstract java.lang.String getFirstName();
public abstract java.lang.String getTitle();
public abstract java.lang.String getTitleOfCourtesy();
public abstract java.sql.Timestamp getBirthDate();
public abstract java.sql.Timestamp getHireDate();
public abstract java.lang.String getAddress();
public abstract java.lang.String getCity();
public abstract java.lang.String getRegion();
public abstract java.lang.String getPostalCode();
public abstract java.lang.String getCountry();
public abstract java.lang.String getHomePhone();
public abstract java.lang.String getExtension();
public abstract byte[] getPhoto();
public abstract String getNotes();
public abstract java.lang.Integer getReportsTo();
public abstract java.lang.String getPhotoPath();
public void ejbLoad()
{
/**@todo Complete this method*/
}
public void ejbStore()
{
/**@todo Complete this method*/
}
public void ejbActivate()
{
/**@todo Complete this method*/
}
public void ejbPassivate()
{
/**@todo Complete this method*/
}
public void unsetEntityContext()
{
this.entityContext = null;
}
public void setEntityContext(EntityContext entityContext)
{
this.entityContext = entityContext;
}
}
EmployeesHome.java:
package cmpdemo;import javax.ejb.*;
import java.util.*;public interface EmployeesHome extends javax.ejb.EJBLocalHome
{
public Employees create(Integer employeeID) throws CreateException;
public Employees findByPrimaryKey(Integer employeeID) throws FinderException;
}EmployeesRemote.java:
package cmpdemo;import javax.ejb.*;
import java.util.*;
import java.rmi.*;
import java.sql.*;public interface EmployeesRemote extends javax.ejb.EJBObject
{
public Integer getEmployeeID() throws RemoteException;
public void setLastName(String lastName) throws RemoteException;
public String getLastName() throws RemoteException;
public void setFirstName(String firstName) throws RemoteException;
public String getFirstName() throws RemoteException;
public void setTitle(String title) throws RemoteException;
public String getTitle() throws RemoteException;
public void setTitleOfCourtesy(String titleOfCourtesy) throws RemoteException;
public String getTitleOfCourtesy() throws RemoteException;
public void setBirthDate(Timestamp birthDate) throws RemoteException;
public Timestamp getBirthDate() throws RemoteException;
public void setHireDate(Timestamp hireDate) throws RemoteException;
public Timestamp getHireDate() throws RemoteException;
public void setAddress(String address) throws RemoteException;
public String getAddress() throws RemoteException;
public void setCity(String city) throws RemoteException;
public String getCity() throws RemoteException;
public void setRegion(String region) throws RemoteException;
public String getRegion() throws RemoteException;
public void setPostalCode(String postalCode) throws RemoteException;
public String getPostalCode() throws RemoteException;
public void setCountry(String country) throws RemoteException;
public String getCountry() throws RemoteException;
public void setHomePhone(String homePhone) throws RemoteException;
public String getHomePhone() throws RemoteException;
public void setExtension(String extension) throws RemoteException;
public String getExtension() throws RemoteException;
public void setPhoto(byte[] photo) throws RemoteException;
public byte[] getPhoto() throws RemoteException;
public void setNotes(String notes) throws RemoteException;
public String getNotes() throws RemoteException;
public void setReportsTo(Integer reportsTo) throws RemoteException;
public Integer getReportsTo() throws RemoteException;
public void setPhotoPath(String photoPath) throws RemoteException;
public String getPhotoPath() throws RemoteException;
}EmployeesRemoteHome.java:
package cmpdemo;import javax.ejb.*;
import java.util.*;
import java.rmi.*;public interface EmployeesRemoteHome extends javax.ejb.EJBHome
{
public EmployeesRemote create(Integer employeeID) throws CreateException, RemoteException;
public EmployeesRemote findByPrimaryKey(Integer employeeID) throws FinderException, RemoteException;
}
package cmpdemo;import java.rmi.*;
import javax.rmi.*;
import javax.naming.*;
import java.util.Properties;
import javax.rmi.PortableRemoteObject;public class EmployeesTestClient1 extends Object
{
private EmployeesRemoteHome employeesRemoteHome = null; //Construct the EJB test client
public EmployeesTestClient1()
{
initialize();
} public void initialize()
{
try
{
//get naming context
Context context = getInitialContext(); //look up jndi name
Object ref = context.lookup("EmployeesRemote");
//look up jndi name and cast to Home interface
employeesRemoteHome = (EmployeesRemoteHome)PortableRemoteObject.
narrow(ref, EmployeesRemoteHome.class);
}
catch(Exception e)
{
e.printStackTrace();
}
} private Context getInitialContext() throws Exception
{
String url = "t3://cne5:7001";
String user = null;
String password = null;
Properties properties = null;
try
{
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if(user != null)
{
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS,
password == null ? "" : password);
} return new InitialContext(properties);
}
catch(Exception e)
{
System.out.println("Unable to connect to WebLogic server at " + url);
System.out.println("Please make sure that the server is running.");
throw e;
}
} public void executeRemoteCallsWithDefaultArguments(EmployeesRemote
employeesRemote)
{
if(employeesRemote == null)
{
return;
}
try
{
employeesRemote.getEmployeeID();
employeesRemote.setLastName("");
employeesRemote.getLastName();
employeesRemote.setFirstName("");
employeesRemote.getFirstName();
employeesRemote.setTitle("");
employeesRemote.getTitle();
employeesRemote.setTitleOfCourtesy("");
employeesRemote.getTitleOfCourtesy();
employeesRemote.setBirthDate(null);
employeesRemote.getBirthDate();
employeesRemote.setHireDate(null);
employeesRemote.getHireDate();
employeesRemote.setAddress("");
employeesRemote.getAddress();
employeesRemote.setCity("");
employeesRemote.getCity();
employeesRemote.setRegion("");
employeesRemote.getRegion();
employeesRemote.setPostalCode("");
employeesRemote.getPostalCode();
employeesRemote.setCountry("");
employeesRemote.getCountry();
employeesRemote.setHomePhone("");
employeesRemote.getHomePhone();
employeesRemote.setExtension("");
employeesRemote.getExtension();
employeesRemote.setPhoto(null);
employeesRemote.getPhoto();
employeesRemote.setNotes("");
employeesRemote.getNotes();
employeesRemote.setReportsTo(null);
employeesRemote.getReportsTo();
employeesRemote.setPhotoPath("");
employeesRemote.getPhotoPath();
}
catch(Exception e)
{
e.printStackTrace();
}
} //----------------------------------------------------------------------------
// Utility Methods
//---------------------------------------------------------------------------- public EmployeesRemoteHome getHome()
{
return employeesRemoteHome;
}
//Main method public static void main(String[] args)
{
try
{
EmployeesTestClient1 remote = new EmployeesTestClient1();
EmployeesRemoteHome home = remote.getHome();
EmployeesRemote client = home.findByPrimaryKey(new Integer(1));
/*if(client.employeesRemote == null)
{
System.out.println(
"Error in testRemoteCallsWithDefaultArguments(): " +
ERROR_NULL_REMOTE);
return;
}*/
System.out.println("EmployeeId:" + client.getEmployeeID());
System.out.println("LastName:" + client.getLastName());
System.out.println("FirstName:" + client.getFirstName());
System.out.println("Title:" + client.getTitle());
System.out.println("TitleOfCourtesy:" + client.getTitleOfCourtesy());
System.out.println("BirthDate:" + client.getBirthDate());
System.out.println("HireDate:" + client.getHireDate());
System.out.println("Address:" + client.getAddress());
System.out.println("City:" + client.getCity());
System.out.println("Region:" + client.getRegion());
System.out.println("PostalCode:" + client.getPostalCode());
System.out.println("Country:" + client.getCountry());
System.out.println("HomePhone:" + client.getHomePhone());
System.out.println("Extension:" + client.getExtension());
System.out.println("Photo:" + client.getPhoto());
System.out.println("Notes:" + client.getNotes());
System.out.println("ReportsTo:" + client.getReportsTo());
System.out.println("PhotoPath:" + client.getPhotoPath());
}
catch (RemoteException ex)
{
ex.printStackTrace();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}