Create an RMI based Examination server of Punjab University that will display the status of a student (Pass/ Fail) upon accept the roll number from client. The server will take "rollNo" of type string as an input from client and can will return his/her status. Suppose you have got find (String) method on server side for the searching of student's status. The client should display the status on console.
RMI Interface:
import java.rmi.*;public interface ExamInt extends Remote
{
String find(String roll_n) throws RemoteException ;
}
Interface Implementation:
import java.rmi.server.*;import java.rmi.*;
import java.sql.*;
public class ExamServerImpl extends UnicastRemoteObject implements ExamInt
{
public ExamServerImpl() throws RemoteException
{
}
//implementation of find(String) not required in asked question...
public String find(String roll_no) throws RemoteException
{
String status;
status=Examjdbc(roll_no);
return status;
}
public String Examjdbc(String r_no) throws RemoteException
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn=DriverManager.getConnection("Jdbc:Odbc:mobileDSN");
Statement st=cn.createStatement();
ResultSet rs=st.executeQuery("Select *from status");
while(rs.next())
{
if(rs.getString(1).equals(r_no))
return rs.getString(2);
}
}
catch(Exception e)
{
System.out.println(e);
}
return null;
}
}
Server:
import java.net.*;import java.rmi.*;
public class ExamServer
{
public static void main(String args[])
{
try{
ExamServerImpl obj= new ExamServerImpl();
Naming.rebind("ExamServer",obj);
}
catch(Exception e)
{
System.out.println("Exception "+e);
}
}
}
Client:
import javax.swing.*;import java.rmi.*;
import java.net.*;
public class ExamClient
{
public static void main(String args[])
{
try{
String examServerURL = "rmi://" + args[0] + "/ExamServer";
ExamInt obj= (ExamInt)Naming.lookup(examServerURL);
String r_n=JOptionPane.showInputDialog("Enter Roll number:");
String Status=obj.find(r_n);
System.out.println("You are " + Status);
}
catch(Exception e)
{
System.out.print("Exception " + e);
}
}
No comments:
Post a Comment
If you have any doubt please let me know