Retornar valor de um ResultSet por RMI

Ola a todos,

Pessoal eu não estou sabendo retorna o valor desse metodo para um cliente RMI. Funciona assim, eu tenho que enviar o resultado desse ResultSet por RMI, sei que não é a maneira mais convencional de se fazer isso, mas é uma nescessidade. Estou tentando fazer dessa forma, sei que vai da erro:

Aqui é a implementação:

import java.io.Serializable;
import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

public class TabelaImpl extends UnicastRemoteObject implements Tabela{

        private String nome;

        public TabelaImpl(String s) throws java.rmi.RemoteException {
               super();
               nome = s;
        }
//aqui é onde estou tentando passar o valor por RMI
    public List Dados() throws RemoteException {
        List listResult = new ArrayList();
        try {
            return Dados2(listResult);
        } catch (SQLException ex) {
            Logger.getLogger(TabelaImpl.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(TabelaImpl.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

        	class Impressao implements Serializable {
                    private String cod_cliente;
                    private String nom_cliente;

                    public String getCodigo() {
                            return cod_cliente;
                    }

                    public String getNome() {
                            return nom_cliente;
                    }

                    public void setCodigo(String codigo) {
                            this.cod_cliente = codigo;
                    }

                    public void setNome(String nome) {
                            this.nom_cliente = nome;
                    }
                }
                
        public String sayHello() throws RemoteException {
               return "Estamos funcionando !!!";
        }

      public List Dados2(List nome) throws RemoteException, SQLException, ClassNotFoundException {
                    List listResultado = new ArrayList();
                    String driver  = "org.postgresql.Driver";
                    String user    = "amplus-super";
                    String senha   = "ds25lk91";
                    String url     = "jdbc:postgresql://localhost:5432/amplus";
                    Connection con = null;
                    Statement stm = null;

                        try {

                            Class.forName("org.postgresql.Driver");
                            con = (Connection) DriverManager.getConnection(url, user, senha);
                            stm = (Statement) con.createStatement();
                            String SQL = "Select * from impressao_biblioteca";
                            ResultSet rs = stm.executeQuery(SQL);

                        int x = 0;
                        Impressao impressao = null;
                        while(rs.next()){
                            impressao = new Impressao();
                            impressao.setCodigo(rs.getString(1));
                            impressao.setNome(rs.getString(2));
                            listResultado.add(impressao);
                            x = x + 1;
                         }
			stm.close();
			return listResultado;
                    }catch ( SQLException sqlex ) {
			sqlex.printStackTrace();
			return listResultado;
                    }
    }


        public static void main(String[] args) throws ClassNotFoundException, SQLException {

         Registry registry = null;

         try {

             registry = LocateRegistry.createRegistry(1099);

            } catch (RemoteException e) {

                 try {
                     registry = LocateRegistry.getRegistry();
                 } catch (RemoteException e2) {

                     System.err.println("Registro não pode ser inicializado");
                     System.exit(0);
                 }
            }
               try {
                       System.setProperty( "java.rmi.server.hostname", "192.168.0.215" );
                       TabelaImpl obj = new TabelaImpl("HelloServer");
                       registry.bind("HelloServer", obj);
                       System.out.println("TabelaImpl foi criado e registrado");
                       System.out.println();

               }

               catch(Exception e) {
                       System.out.println("Ocorreu uma exceção no servidor");
                       e.printStackTrace();
               }
        }
}

Aqui é a interface


import java.util.List;


public interface Tabela extends java.rmi.Remote {

        String sayHello() throws java.rmi.RemoteException;
        List Dados() throws java.rmi.RemoteException;
}

Aqui é o cliente

import java.rmi.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.ArrayList;
import java.util.List;

public class TabelaClient {
        public TabelaClient(){
        }
	public static void main(String[] args) throws java.net.UnknownHostException {

        String mensagem = "";
        List listResult = new ArrayList();
               try {
                        
                        Registry registry = LocateRegistry.getRegistry("192.168.0.215", 1099);
                        Tabela obj = (Tabela) Naming.lookup("rmi://192.168.0.215:1099/HelloServer");
                        mensagem = obj.sayHello();
                        List dados = obj.Dados();
                        System.out.println(mensagem);
                        System.out.println(dados);

               }catch(Exception e) {
                       System.out.println("Ocorreu uma exceção");
                       System.out.println (java.net.InetAddress.getLocalHost() );
                       e.printStackTrace();
               }
        }

}

Agradeço Qualquer ajuda
Antonio

eu consigo acessar o banco do lado do servidor tranquilamente, só que ro uma dica de como levar o resultada da query para o cliente através de RMI.

Caro antoniosales,

Posta qual o erro que esta acontecendo, uma dica tenta tipar a sua lista, talvez possa ajudar.
Exemplo

List<Impressao> lista = new ArrayList<Impressao>();

Como estou fazendo abaixo, não da erro nenhum, simplesmente o servidor não retorna nada da base de dados para o cliente:

Servidor:

import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;

public class ServerImpl extends UnicastRemoteObject implements Interface{

        private Impressao ImpressaInformacao[];
        private String nome;

        public ServerImpl(String s) throws java.rmi.RemoteException {
               super();
               nome = s;
               RecebeImpressao();
        }

                private void RecebeImpressao() throws RemoteException
                {
                    try{

                    String driver  = "org.postgresql.Driver";
                    String user    = "amplus-super";
                    String senha   = "ds25lk91";
                    String url     = "jdbc:postgresql://192.168.0.215:5432/amplus";
                    Connection con = null;
                    Statement stm = null;

                            Class.forName("org.postgresql.Driver");
                            con = (Connection) DriverManager.getConnection(url, user, senha);
                            stm = (Statement) con.createStatement();
                            String SQL = "Select * from impressao_biblioteca";
                            ResultSet rs = stm.executeQuery(SQL);

                        Vector Resultado = new Vector();
                        Impressao impressao = null;

                        while(rs.next()){
                            Impressao w = new Impressao(rs.getString(1), rs.getString(2));
                            Resultado.addElement( w );
                         }
                        ImpressaInformacao = new Impressao[ Resultado.size() ];

                        for ( int i = 0; i < ImpressaInformacao.length; i++ ){
                           ImpressaInformacao[ i ] = ( Impressao ) Resultado.elementAt( i );
                        }
			stm.close();
                    }catch(Exception e){
                        e.printStackTrace();
                        System.exit( 1 );
                    }
                }

                public Impressao[] getImpressao(){
                    return ImpressaInformacao;
                }

        public String sayHello() throws RemoteException {
               return "Estamos funcionando !!!";
        }

         public static void main(String[] args) throws ClassNotFoundException, SQLException {

         Registry registry = null;

         try {

             registry = LocateRegistry.createRegistry(1099);

            } catch (RemoteException e) {

                 try {
                     registry = LocateRegistry.getRegistry();
                 } catch (RemoteException e2) {

                     System.err.println("Registro não pode ser inicializado");
                     System.exit(0);
                 }
            }

               try {
                       System.setProperty( "java.rmi.server.hostname", "192.168.0.215" );
                       ServerImpl obj = new ServerImpl("ObjetoServer");
                       registry.bind("ObjetoServer", obj);
                       System.out.println("ServidorRMI foi criado e registrado");
                       
               }

               catch(Exception e) {
                       System.out.println("Ocorreu uma exceção no servidor");
                       e.printStackTrace();
               }
        }
}

Interface:

import java.rmi.*;
import remoto.Impressao;

public interface Interface extends java.rmi.Remote {
        String sayHello() throws java.rmi.RemoteException;
        public Impressao[] getImpressao() throws RemoteException;
}

Impressao

import java.io.Serializable;

    public class Impressao implements Serializable {
        private String cod_cliente;
        private String nom_cliente;
        public Impressao( String codigo, String nome)
        {
                cod_cliente = codigo;
                nom_cliente = nome;
        }
        public String getNome() { return nom_cliente; }
        public String getCodigo() { return cod_cliente; }
    }

Cliente

import java.rmi.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import remoto.Impressao;

public class Client {

        public Client(){
        }
	public static void main(String[] args) throws java.net.UnknownHostException {

        String mensagem = "";
        StringBuilder Dados = new StringBuilder();
               try {
                        
                        Registry registry = LocateRegistry.getRegistry("192.168.0.215", 1099);
                        Interface obj = (Interface) Naming.lookup("rmi://192.168.0.215:1099/ObjetoServer");
                        mensagem = obj.sayHello();
                        
                        Impressao w[] = obj.getImpressao();

                        for ( int i = 0; i < w.length; i++ ) {
                            
                         Dados.append( w[ i ] );
                            
                        }

                        System.out.println(mensagem);
                        System.out.println(Dados);
               }catch(Exception e) {
                       System.out.println("Ocorreu uma exceção");
                       System.out.println (java.net.InetAddress.getLocalHost() );
                       e.printStackTrace();
               }
        }

}