ResultSet错误java.rmi.UnmarshalException

时间:2015-04-02 10:48:46

标签: java database sqlite rpc

我正在尝试在服务器端执行查询并将结果发送到客户端,但在将值返回给客户端时发生错误 我试图使用RPC协议实现这一点但我无法找到如何将结果集从服务器发送回客户端并使用sqlite数据库

客户端:

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);
    }



   }
}

服务器:

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;
    }

}

1 个答案:

答案 0 :(得分:0)

ResultSet不可序列化吗?因此,将结果添加到可序列化的DTO中,然后将其传回