我正在实施银行系统,我想向客户端发送ResultSet
。但Java给我看错了。
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
答案 0 :(得分:0)
运气不好,你不能。我想发送
ResultSet
ResultSet
不是Serializable
。
或客户端的连接对象,实际上后者不是一个好主意。
这不仅不是一个“好主意”,而且是一个完全没有意义的想法。您不能通过电话线发送电话。同样,您无法通过其他连接发送连接。更不用说Connection
也不是Serializable
的事实。
但是,Java给我看错了。
下次在任何地方发布问题报告时,请确保包含实际问题,包括错误消息,逐字,剪切和粘贴,而不是手动转录,连同源代码的相关部分,必要时转录行号,以及预期和实际产出。
catch(){
}
从不忽略异常。否则你将调试变成一场猜谜游戏。
答案 1 :(得分:-1)
好的,在我完成一些研究后,我会尝试回答我自己的问题。我已经解决了这些问题。
错误是发送未序列化的对象。
因为,ResultSet不支持序列化我还创建了一个Model类和Return 客户端的模型类对象列表。通过将序列化添加到要作为参数传输的每个类,还包括骨架实现序列化,请注意,所有类都需要在客户端定义。
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());
}
}
}
ALl上面的方法工作得很好。但是,这里的问题是我想将模型类的列表绑定到jtable模型。我可以传递适合TableModel的列吗?