2013-05-29 80 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

相關問題