2013-05-29 74 views
0

我正在实施银行系统,并且我想向客户端发送ResultSet。但Java给我一个错误。使用seralization从RMI服务器和客户端发送和接收对象

public interface SekelatonInterface extends Remote { 

    public String test() throws RemoteException; // this is ok it works fine 

    public ConnectionClass getConnection() throws RemoteException; //shows error on  client call 

    public ResultSet getAllDeposits(Integer CustomerId) throws RemoteException; 
    } 

    public class SekelatonImpl extends UnicastRemoteObject implements SekelationInterface { 



    SekelatonImpl() throws RemoteException{ 

    } 

       //sekelaton implemeation 
    public ConnectionClass getConnection() { 

    try { 
    dbobject = new ConnectionClass(); 
     dbobject.connectDb(); 
    dbObject.setQuery("select * from cutomer"); 
     return dbobject; //this method is on connection class ,dont be confuse 

    } 

    catch(Exception ex) 

      { 

     System.out.println("Error :"+ex.getMessage()); 
      } 

    } 

    } 

    public class Server { 


    public void PackServerandRun(String SecurityFilePath,Integer port,String rmiUrl) { 


    //do rmi registery stuff and run server 
    SekelatonImpl databaseObject = new SekelationImpl(); // rebind this object 

    } 

} 
    cleintstub.test(); //this recive the server message or works fine 
    cleintStub.getConnection(); //why couldn't i get a ConnectionClass Object ? 

当我运行客户端,我看到的错误是:

注册表查找有错误错误拆封返回头部;嵌套的例外是:java.io.EOFException的

+1

和什么是错误?发布堆栈跟踪 – WeMakeSoftware

回答

0

好的,我会尝试回答我自己的问题后,我经历了一些研究,我已经解决了问题。

错误是发送未序列化的对象。

因为ResultSet不支持序列化我还创建了一个Model类并返回 将模型类对象列表添加到客户端。通过向要传输的每个类添加序列化作为参数,还包括您的骨架实现序列化,请注意,所有的类都需要在客户端定义。

public class ConnectionClass implements java.io.Serializable { 

} 

public interface SekelatonInterface extends Remote ,java.io.Serializable{ 

public Login getTestClass()throws RemoteException; 

public String test() throws RemoteException; 

public List<Login> getConnection() throws RemoteException; 

public void sayHitoServer(String messages) throws RemoteException; 

} 
public class SkeletonInterfaceImpl extends UnicastRemoteObject implements  SekelatonInterface,Serializable { 

    //implement all your skeleton methods 
} 

//this to change result set into model class to transefer it to client 

public class Login { 

private int Id; 

private String Username; 

private String Password; 

public Login() { 

} 

public int getId() { 
    return Id; 
} 

public void setId(int Id) { 
    this.Id = Id; 
} 

public String getUsername() { 
    return Username; 
} 

public void setUsername(String Username) { 
    this.Username = Username; 
} 

public String getPassword() { 
    return Password; 
} 

public void setPassword(String Password) { 
    this.Password = Password; 
} 

public Login(ResultSet resultset){ 
    try{ 
    // resultset.next(); 
    Id = resultset.getInt("LoginId"); 
    Username =resultset.getString("Uname"); 
    Password = resultset.getString("Password"); 
      } 
    catch(Exception ex){ 
    JOptionPane.showMessageDialog(null, "Error Setting Up Login"+ex.getMessage()); 

    } 
    } 
} 

所有上述方法将工作得fine.But,这里的问题是我想要的模型类的列表绑定到一个JTable model.how我可以通过适合的TableModel列?

0

我想送ResultSet

运气不好,你不能。 ResultSet不是Serializable

或连接对象到客户端,实际上后来是不是好主意。

这不仅是一个'好主意',它是一个完全没有意义的想法。你不能通过电话线发送电话。同样,您不能通过另一个连接发送连接。更不用说Connection也不是Serializable

但是,Java给我显示了一个错误。

下一次您发布问题报告,在任何地方,一定要包括实际问题,包括错误消息,逐字,剪切和粘贴,没有人工转录,与相关部门一起的源代码,必要时显示行号,以及预期和实际的输出。

catch(){ 
    } 

决不忽略一个例外。否则,你会将调试转变成一个猜测游戏。

+0

好的,谢谢!但你建议发送一个数据库的结果实际上如何返回不结果集本身,但如何使其可串行化? – danielad

+0

你可以从你的ResultSet创建一个Map >,它由外层的唯一键和内层的列名建立索引。或者你可以看看创建'WebRowSet'并从中创建一个XML文档,并将其作为一个字符串返回;但在我看来,这是对RMI的糟糕使用。您应该将数据保存在服务器上并提供 – EJP

相关问题