0

I have been trying real hard to connect JDBC with RMI. In that i need to retrieve the database result into the client console screen.I thought of passing the ResultSet object from Remote method to the client. I dont know how to do it. Help!

import java.rmi.*;
import java.rmi.server.*;
import java.sql.*;
import java.io.Serializable;

public class Infoimp extends UnicastRemoteObject implements Infoint,java.io.Serializable
{
    public Infoimp() throws RemoteException{
    }
    public ResultSet result() throws RemoteException
    {
        try{
                final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
                final String DB_URL = "jdbc:mysql://localhost:3306/STUDENTS";
                final String USER = "root";
                final String PASS = "";
                Class.forName("com.mysql.jdbc.Driver");
                Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
                String sql = "INSERT INTO INFO VALUES (1011,'GEET','IT',8735007)";
                Statement stmt = conn.createStatement();
                boolean x=stmt.execute(sql);

                sql="SELECT * FROM INFO";
                ResultSet rs = stmt.executeQuery(sql);

                return(rs);
        }catch(Exception se){
            se.printStackTrace();

            ResultSet rs=null;
            return(rs);
        }   
    }
}

1 Answers1

0

You can't pass Resultset, which is not Serializable. Get values from Resultset into plain java object, which is Serializable and pass that object.

Have a look at oracle documentation.

If you need sample code to achieve this, have a look at SE question:

How to pass object in arguments in RMI method?

Community
  • 1
  • 1
Ravindra babu
  • 37,698
  • 11
  • 250
  • 211