Hi, my name is John.I am registered user of javaranch.com
I am facing a problem of RMI Object Serialization.From a server program I want to pass an Object as a parameter but I can't serialize the object.Plz help me.Send me a good material on Object Serialization.
Interface
--------------
import java.rmi.*;
import java.sql.*;
public interface Interface2 extends Remote
{
String getcustid(String s1) throws RemoteException;
ResultSet display() throws RemoteException;
}
Server program
-----------------
import java.io.Serializable;
import java.sql.*;
import java.rmi.*;
import java.rmi.server.*;
public class JdbcServer extends UnicastRemoteObject implements Interface2,Serializable
{
Connection c;
Statement s;
transient ResultSet r;
String s2;
public String getcustid(String s1) throws RemoteException
{
s2=s1;
return s2;
}
public ResultSet display() throws RemoteException
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
c=DriverManager.getConnection("Jdbc
dbc:EBANKING","db2admin","db2admin");
s=c.createStatement();
r=s.executeQuery("SELECT * from CURRENTAC,BRANCH where CURRENTAC.BRANCHID=BRANCH.BRANCHID AND CURRENTAC.CUSTOMERID='" +s2+ "'");
}catch(Exception e1){System.out.println(e1);}
return r;
}
JdbcServer() throws RemoteException
{}
public static void main(String args[])
{
try{
JdbcServer js = new JdbcServer();
System.out.println("connecting to server.....");
Naming.rebind("rmi://localhost:1099/Balanceenq",js);
System.out.println("Server Registered and Ready");
}catch(Exception e){System.out.println(e);}
}
}
Client Program
--------------------
import java.rmi.*;
import java.sql.*;
import java.io.*;
public class JdbcClient
{
public static void main(String args[])
{
ResultSet Result;
try{
Interface2 ref=(Interface2)Naming.lookup("rmi://localhost:1099/Balanceenq");
ref.getcustid("john_p2");
Result=ref.display();
while(Result.next())
{
System.out.println("Account Number::" +Result.getString("ACCNO"));
System.out.println("Balance::" +Result.getString("BALANCE"));
System.out.println("Branch id::" +Result.getString("BRANCHID"));
System.out.println("---------------------------------------");
}
}catch(Exception e){System.out.println(e);}
}
}