aspose file tools*
The moose likes JDBC and the fly likes How to Fetch The Record From the Client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to Fetch The Record From the Client " Watch "How to Fetch The Record From the Client " New topic
Author

How to Fetch The Record From the Client

Yogesh MSharma
Greenhorn

Joined: Jun 24, 2001
Posts: 7
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);}
}
}

With LUV
Mohamed Yousuff
Ranch Hand

Joined: Jun 23, 2001
Posts: 73

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

Joined: Jun 24, 2001
Posts: 7
Hi
I dont Know how to use serizble class..
Would you make some change in my code
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Fetch The Record From the Client
 
Similar Threads
rmi and resultset
NULL POINTER eXCEPTION
Problem in bmp entity bean while running client?
visual J++ and retreiving rows from sql server
RMI Object Serialization problem