• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

How to Fetch The Record From the Client

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I have written a RMI application where i want to fetch the REcord from the Other Machine.But i t is not Woring
Code is as given Below
It throws MarshelException
Code is
import java.rmi.*;
import java.sql.*;
public interface AddServerIntf2 extends Remote{
ResultSet disp(String name)throws RemoteException;
}
import java.rmi.*;
import java.rmi.server.*;
import java.sql.*;
public class AddServerImpl2 extends UnicastRemoteObject
implements AddServerIntf2{
public AddServerImpl2() throws RemoteException{
}
//void disp(String name,ResultSet rs1) throws RemoteException
public ResultSet disp(String name) throws RemoteException
{
String url="jdbc dbc:group";
ResultSet rs1=null;
Connection c;
PreparedStatement ps;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
c=DriverManager.getConnection(url);
name="select * from "+name;
ps=c.prepareStatement(name);
return(rs1=ps.executeQuery());

}
catch(SQLException se){System.out.println("SQLException : "+se); }
catch(Exception e){System.out.println("Exception : "+e);}
return rs1;
}
}

import java.rmi.*;
import java.net.*;
public class AddServer2 {
public static void main(String ar[]){
try{
AddServerImpl2 a2=new AddServerImpl2();
Naming.rebind("AddServer2",a2);
}
catch(Exception e){System.out.println("Exception Caught : "+e);}
}
}import java.rmi.*;
import java.sql.*;
public class AddClient2{
public static void main(String ar[]){
try{
String URL="rmi://"+ar[0]+"/AddServer2";
AddServerIntf2 aa = (AddServerIntf2) Naming.lookup(URL);
System.out.println("Records from "+ar[1]);
System.out.println("Rollno Name");
ResultSet rs=aa.disp(ar[1]);
if(rs!=null)
{
while(rs.next()){
int i=rs.getInt("rollno");
String ss=rs.getString("name");
System.out.println(i+" "+ss);
}
}
}
catch(Exception e){System.out.println("Exception Caught : "+e);}
}
}
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Remember that the type of arguments or return type of an RMI method should be serializable ( except primitive data type ). You are trying to return a ResultSet object which is not serializable. Hence it throws exception.
Actually, your problem came as a surprise for me since I tried the same technique in one of my projects and experienced the same trouble. It was only then that I referred to the documentation and figured out the problem.

I have already suggested a solution to this problem. Visit the link http://www.javaranch.com/ubb/Forum3/HTML/001195.html


------------------
 
Yogesh MSharma
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I dont Know how to use serizble class..
Would you make some change in my code
 
I like you because you always keep good, crunchy cereal in your pantry. This tiny ad agrees:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic