各位大侠:
我现在给大家更清楚的解释,我举一个例子,我现在发现是的错误:
我下面的这段代码,绝对是真确的(已经实验过):
int i=0;
while (i<11)
{
v.addElement(new Integer(i));
//addElementdo
esn't
i++;
}
/*
* Return an enumeration of found primary keys
*/
java.util.Enumeration e=v.elements();
while(e.hasMoreElements())
{
System.out.println("Elements:"+e.nextElement()+"/");
}
结果使这样的:
Elements:0/
Elements:1/
Elements:2/
Elements:3/
Elements:4/
Elements:5/
Elements:6/
Elements:7/
Elements:8/
Elements:9/
Elements:10/
可是我把这段代码作为EJB的远程方法的一部分时,就出现错误
假设有一个EJB的方法:
public java.util.Enumeration ejbFindByOwnerName(String name) throws
FinderException, RemoteException {
PreparedStatement pstmt = null;
Connection conn = null;
Vector v = new Vector();
try {
System.out.println("ejbFindByOwnerName(" + name + ") called");
/*
* Acquire DB connection
*/
conn = getConnection();
/*
* Find the primary keys in the DB
*/
pstmt = conn.prepareStatement(
"select id from accounts where ownerName = ?");
pstmt.setString(1, name);
ResultSet rs = pstmt.executeQuery();
/*
* Insert every primary key found into a vector
*/
int i=0;
while (rs.next()) {
String id = rs.getString("id");
//AccountPK tempPK=new AccountPK(id);
//v.addElement(tempPK);
v.addElement(new Integer(i));
//addElementdo
esn't
i++;
}
在客户端调用这个方法时:
Context ctx = new InitialContext();
//look up jndi name
Object ref = ctx.lookup("Account");
//cast to Home interface
AccountHome home = (AccountHome) PortableRemoteObject.narrow(ref, AccountHome.class);
home.create("13-459967-8799","John Smith");
String name="John Smith";
java.util.Enumeration e=home.findByOwnerName("John Smith");
//account=(Account)home.findByPrimaryKey(new AccountPK("123-456-7899"));
//System.out.println("test zhf");
while(e.hasMoreElements())
{
System.out.println("Elements:"+e.nextElement()+"/");
}
在服务器段:
输出是真确的(如我前所述)
而在客户端出现下面的结果:
Elements:Stub[repository_id=RMI:bankentitybean.Account:0000000000000000,key=ServiceId[service=/EJB[ejbcontainer]Account,id={68 bytes: (127)(255)(255)(2)(0)(0)(0)[8][R][M][:][j][a][v][a][.][l][a][n][g][.][n][t][e][g][e][r][:][6][4][D][4][7][C][1][D][0][1][9][8][0][5][E][:][1][2][E][2][A][0][A][4][F][7][8][1][8][7][3][8](0)(0)(0)(0)(0)}],codebase=null]/
Elements:Stub[repository_id=RMI:bankentitybean.Account:0000000000000000,key=ServiceId[service=/EJB[ejbcontainer]Account,id={68 bytes: (127)(255)(255)(2)(0)(0)(0)[8][R][M][:][j][a][v][a][.][l][a][n][g][.][n][t][e][g][e][r][:][6][4][D][4][7][C][1][D][0][1][9][8][0][5][E][:][1][2][E][2][A][0][A][4][F][7][8][1][8][7][3][8](0)(0)(0)(0)(1)}],codebase=null]/
Elements:Stub[repository_id=RMI:bankentitybean.Account:0000000000000000,key=ServiceId[service=/EJB[ejbcontainer]Account,id={68 bytes: (127)(255)(255)(2)(0)(0)(0)[8][R][M][:][j][a][v][a][.][l][a][n][g][.][n][t][e][g][e][r][:][6][4][D][4][7][C][1][D][0][1][9][8][0][5][E][:][1][2][E][2][A][0][A][4][F][7][8][1][8][7][3][8](0)(0)(0)(0)(2)}],codebase=null]/
Elements:Stub[repository_id=RMI:bankentitybean.Account:0000000000000000,key=ServiceId[service=/EJB[ejbcontainer]Account,id={68 bytes: (127)(255)(255)(2)(0)(0)(0)[8][R][M][:][j][a][v][a][.][l][a][n][g][.][n][t][e][g][e][r][:][6][4][D][4][7][C][1][D][0][1][9][8][0][5][E][:][1][2][E][2][A][0][A][4][F][7][8][1][8][7][3][8](0)(0)(0)(0)(3)}],codebase=null]/
Elements:Stub[repository_id=RMI:bankentitybean.Account:0000000000000000,key=ServiceId[service=/EJB[ejbcontainer]Account,id={68 bytes: (127)(255)(255)(2)(0)(0)(0)[8][R][M][:][j][a][v][a][.][l][a][n][g][.][n][t][e][g][e][r][:][6][4][D][4][7][C][1][D][0][1][9][8][0][5][E][:][1][2][E][2][A][0][A][4][F][7][8][1][8][7][3][8](0)(0)(0)(0)(4)}],codebase=null]/
Elements:Stub[repository_id=RMI:bankentitybean.Account:0000000000000000,key=ServiceId[service=/EJB[ejbcontainer]Account,id={68 bytes: (127)(255)(255)(2)(0)(0)(0)[8][R][M][:][j][a][v][a][.][l][a][n][g][.][n][t][e][g][e][r][:][6][4][D][4][7][C][1][D][0][1][9][8][0][5][E][:][1][2][E][2][A][0][A][4][F][7][8][1][8][7][3][8](0)(0)(0)(0)(5)}],codebase=null]/
Elements:Stub[repository_id=RMI:bankentitybean.Account:0000000000000000,key=ServiceId[service=/EJB[ejbcontainer]Account,id={68 bytes: (127)(255)(255)(2)(0)(0)(0)[8][R][M][:][j][a][v][a][.][l][a][n][g][.][n][t][e][g][e][r][:][6][4][D][4][7][C][1][D][0][1][9][8][0][5][E][:][1][2][E][2][A][0][A][4][F][7][8][1][8][7][3][8](0)(0)(0)(0)(6)}],codebase=null]/
Elements:Stub[repository_id=RMI:bankentitybean.Account:0000000000000000,key=ServiceId[service=/EJB[ejbcontainer]Account,id={68 bytes: (127)(255)(255)(2)(0)(0)(0)[8][R][M][:][j][a][v][a][.][l][a][n][g][.][n][t][e][g][e][r][:][6][4][D][4][7][C][1][D][0][1][9][8][0][5][E][:][1][2][E][2][A][0][A][4][F][7][8][1][8][7][3][8](0)(0)(0)(0)(7)}],codebase=null]/
Elements:Stub[repository_id=RMI:bankentitybean.Account:0000000000000000,key=ServiceId[service=/EJB[ejbcontainer]Account,id={68 bytes: (127)(255)(255)(2)(0)(0)(0)[8][R][M][:][j][a][v][a][.][l][a][n][g][.][n][t][e][g][e][r][:][6][4][D][4][7][C][1][D][0][1][9][8][0][5][E][:][1][2][E][2][A][0][A][4][F][7][8][1][8][7][3][8](0)(0)(0)(0)(8)}],codebase=null]/
Elements:Stub[repository_id=RMI:bankentitybean.Account:0000000000000000,key=ServiceId[service=/EJB[ejbcontainer]Account,id={68 bytes: (127)(255)(255)(2)(0)(0)(0)[8][R][M][:][j][a][v][a][.][l][a][n][g][.][n][t][e][g][e][r][:][6][4][D][4][7][C][1][D][0][1][9][8][0][5][E][:][1][2][E][2][A][0][A][4][F][7][8][1][8][7][3][8](0)(0)(0)(0)(9)}],codebase=null]/
Elements:Stub[repository_id=RMI:bankentitybean.Account:0000000000000000,key=ServiceId[service=/EJB[ejbcontainer]Account,id={68 bytes: (127)(255)(255)(2)(0)(0)(0)[8][R][M][:][j][a][v][a][.][l][a][n][g][.][n][t][e][g][e][r][:][6][4][D][4][7][C][1][D][0][1][9][8][0][5][E][:][1][2][E][2][A][0][A][4][F][7][8][1][8][7][3][8](0)(0)(0)(0)(10)}],codebase=null]/
Elements:Stub[repository_id=RMI:bankentitybean.Account:0000000000000000,key=ServiceId[service=/EJB[ejbcontainer]Account,id={68 bytes: (127)(255)(255)(2)(0)(0)(0)[8][R][M][:][j][a][v][a][.][l][a][n][g][.][n][t][e][g][e][r][:][6][4][D][4][7][C][1][D][0][1][9][8][0][5][E][:][1][2][E][2][A][0][A][4][F][7][8][1][8][7][3][8](0)(0)(0)(0)(11)}],codebase=null]/
Elements:Stub[repository_id=RMI:bankentitybean.Account:0000000000000000,key=ServiceId[service=/EJB[ejbcontainer]Account,id={68 bytes: (127)(255)(255)(2)(0)(0)(0)[8][R][M][:][j][a][v][a][.][l][a][n][g][.][n][t][e][g][e][r][:][6][4][D][4][7][C][1][D][0][1][9][8][0][5][E][:][1][2][E][2][A][0][A][4][F][7][8][1][8][7][3][8](0)(0)(0)(0)(12)}],codebase=null]/
Elements:Stub[repository_id=RMI:bankentitybean.Account:0000000000000000,key=ServiceId[service=/EJB[ejbcontainer]Account,id={68 bytes: (127)(255)(255)(2)(0)(0)(0)[8][R][M][:][j][a][v][a][.][l][a][n][g][.][n][t][e][g][e][r][:][6][4][D][4][7][C][1][D][0][1][9][8][0][5][E][:][1][2][E][2][A][0][A][4][F][7][8][1][8][7][3][8](0)(0)(0)(0)(13)}],codebase=null]/
Elements:Stub[repository_id=RMI:bankentitybean.Account:0000000000000000,key=ServiceId[service=/EJB[ejbcontainer]Account,id={68 bytes: (127)(255)(255)(2)(0)(0)(0)[8][R][M][:][j][a][v][a][.][l][a][n][g][.][n][t][e][g][e][r][:][6][4][D][4][7][C][1][D][0][1][9][8][0][5][E][:][1][2][E][2][A][0][A][4][F][7][8][1][8][7][3][8](0)(0)(0)(0)(14)}],codebase=null]/
这是啥原因,这也是我以前说的异常产生的主要原因。