我的第一個entity Ejb就出錯!大家幫幫忙

asdlcj發表於2004-03-20
1.
用jb8+wls70+mssql2000
寫了一個 表employees的entity ejb
用sessionbean分裝,
有一個getEmpName的方法如下,根據empid返回姓名!
public String getEmpName(Integer empID) {
/**@todo Complete this method*/
String empName="name not found!";
try{
javax.naming.Context context=new javax.naming.InitialContext();
Object object=context.lookup("java:comp/env/ejb/Employees");
EmployeesHome empHome=(EmployeesHome)
javax.rmi.PortableRemoteObject.narrow(object,EmployeesHome.class);
Employees emp=empHome.findByPrimaryKey(empID);
empName=emp.getFirstName()+""+emp.getLastName();
}
catch(NamingException ex){
ex.printStackTrace();
}
catch(ClassCastException ex){
ex.printStackTrace();

}
catch(Exception ex){
ex.printStackTrace();

}

return empName;
}
2.配置好wls的資料來源連線池(已經連線成功)和java:comp/env/ejb/Employees引用
執行jb和wls
部署程式
寫了一個testclient
main方法如下
public static void main(String[] args) {
employeesSesTestClient client = new employeesSesTestClient();
// Use the client object to call one of the Home interface wrappers
// above, to create a Remote interface reference to the bean.
// If the return value is of the Remote interface type, you can use it
// to access the remote interface methods. You can also just use the
// client object to call the Remote interface wrappers.
try {
client.create();
String empName=client.getEmpName(new Integer("1"));
System.out.println("Name from the test client="+empName);
}
catch(Exception ex){
ex.printStackTrace();
}
}
執行testcilent
控制檯丟擲錯誤如下
javax.ejb.FinderException: Problem in findByPrimaryKey while preparing or executing statement: 'weblogic.jdbc.rmi.SerialPreparedStatement@6a66b':

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]ResultSet can not re-read row data for column 1.

java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]ResultSet can not re-read row data for column 1.

at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)

at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)


怎麼會事?謝謝

相關文章