RMI Client code Connection problem
Hi all,
I am new to Java RMI programming, so excuse me for stupid question
Problems:
i am not using Application server
-My Remote interface is like this
package Test;
import java.awt.Image;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.Vector;
publicinterface Myinterfaceextends Remote{
publicint getSum(int a,int b)throws RemoteException;
public Vector databaseinteraction()throws RemoteException;
}
-My Server program is as follows
package Test;
import java.awt.Image;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.sql.DriverManager;
import java.sql.Connection;
import java.util.Vector;
import com.mysql.jdbc.ResultSet;
import com.mysql.jdbc.Statement;
publicclass Myserverextends UnicastRemoteObjectimplements Myinterface{
static Statement stmt =null;
static ResultSet result =null;
privatestaticfinallong serialVersionUID = 1;
protected Myserver()throws RemoteException{
super();
}
publicstaticvoid main(String[] args)throws RemoteException{
Myserver server =new Myserver();
try{
Naming.rebind("rmi://192.168.1.24/Myserver",server);
System.out.println("I m registered");
}
catch(Exception e){
System.out.println(e);
}
}
publicint getSum(int a,int b)throws RemoteException{
return a+b;
}
public Vector databaseinteraction()throws RemoteException{
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/test?"+"user=root");
stmt = (Statement) conn.createStatement();
result = (ResultSet) stmt.executeQuery("select * from test1");
Vector results =new Vector();
while (result.next()){
results.add(result.getString(1));
}
conn.close();
return results;
}
catch(Exception e){
System.out.println(e);
}
returnnull;
}
}
Myclient code is as follows
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.Vector;
import java.net.*;
publicclass Myclient{
publicstaticvoid main(String[] args)throws MalformedURLException, RemoteException, NotBoundException{
try{
System.setProperty("java.security.policy","client.policy");
System.setSecurityManager(new RMISecurityManager());
Myinterface server = (Myinterface) Naming.lookup("rmi://192.168.1.24/Myserver");
int result=server.getSum(2,3);
System.out.println("Result:"+result);
Vector resultsvector = (Vector)server.databaseinteraction();
for(int i=0; i < resultsvector.size(); i++){
System.out.println(resultsvector.get(i));
}
}
catch(Exception e){
System.out.println(e);
}
}
}
Client.policy code is
grant
{
permission java.net.SocketPermission
"*:1024-65535","connect";
};
When i try to run the Client program from remote machine its not working
it says
Error
Myinterface cannot be resolved to a type
Please! let me know what i can do to run this code from remote machine

