I am trying to execute the query on server side and send the result to the client but at the time of returning the value to the client the error occurs
Am trying to achieve this using RPC Protocol but i could not find out how to send back the resultset from server to client and am using sqlite database

Client:

public class client {

    public static void main(String[] args) { 
    ResultSet rs;
        try {
            inter Inter = (inter) Naming.lookup("rmi://localhost/collegeDBImpl");
             System.out.println("Handle to Server Object Acquired");  
             BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
             System.out.println("username");
             String username=br.readLine();
             System.out.println("pass");
             String password=br.readLine();
             rs=Inter.loginDB(username, password);
        } catch (NotBoundException ex) {
            Logger.getLogger(client.class.getName()).log(Level.SEVERE, null, ex);
        } catch (MalformedURLException ex) {
            Logger.getLogger(client.class.getName()).log(Level.SEVERE, null, ex);
        } catch (RemoteException ex) {
            Logger.getLogger(client.class.getName()).log(Level.SEVERE, null, ex);
        }catch(Exception e){
            System.out.println(e);
        }



    }
}

Server:

public class server {
    public static void main(String[] args) throws Exception {
                        impl li=new impl();
            System.out.println("Server Started");
            Naming.rebind("collegeDBImpl",li);
            System.out.println("Server Object Registered");
    }

}

inter.java

   public interface inter extends Remote{
         public ResultSet loginDB(String username, String password)throws RemoteException; 
    }

impl.java:

public class impl  extends UnicastRemoteObject  implements inter{

    Connection conn=null;
    ResultSet rs=null;
    PreparedStatement pst = null;
    impl()throws RemoteException{        
        conn=javaConnect.ConnecrDb();
    }

    @Override
    public ResultSet loginDB(String username, String password) throws RemoteException {
        String sql="Select * from studentDetails where username=? and password=?";
       try{
       pst=conn.prepareStatement(sql);
       pst.setString(1, username);
       pst.setString(2, password);
       rs=pst.executeQuery();
       if(rs.next()){
           JOptionPane.showMessageDialog(null, "Username and password is correct");
       }else{
            JOptionPane.showMessageDialog(null, "Username and password is not correct");
       }
       }catch(Exception e){
           JOptionPane.showMessageDialog(null, e);           
       }
       return rs;
    }

}

Edited 1 Year Ago by dendenny01

ResultSet is not serializable. You can only send across things which can be serialized across the wire e.g. List, Set etc. Any reason why you want to send the result set to the user instead of the data inside it?

Ok since ResultSet is not Serializable I have to extract the result in some Arraylist and then transfer it to client ...
thanks a lot

This question has already been answered. Start a new discussion instead.