Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ques 2----------------------------------
- package newP;
- public class Employee implements java.io.Serializable
- {
- private int employeeId;
- private String name;
- float salary;
- public Employee(int employeeId,String name,float salary)
- {
- this.employeeId=employeeId;
- this.name=name;
- this.salary=salary;
- }
- public String toString()
- {
- return employeeId+" "+name+" "+salary;
- }
- }
- --------------------------------------
- package newP;
- import java.rmi.*;
- import java.util.*;
- interface Employee1 extends Remote
- {
- public List<Employee> getEmployee() throws Exception ;
- public void setEmployee(Employee e) throws Exception ;
- }
- ------------------------------------------
- package newP;
- import java.rmi.registry.*;
- import java.rmi.*;
- import java.rmi.server.*;
- import java.util.*;
- class EmployeeClient
- {
- public static void main(String args[]) throws Exception
- {
- int ch;
- // ArrayList<Employee> list=new ArrayList<>();
- Employee1 m = (Employee1)Naming.lookup("rmi://localhost:3333/service");
- Scanner sc = new Scanner(System.in);
- EmployeeImpl e =new EmployeeImpl();
- while(true)
- {
- System.out.println("1.add \n 2.show");
- ch=sc.nextInt();
- if(ch==1)
- {
- System.out.println("Enter id , name ,salary");
- int id=sc.nextInt();
- String name=sc.next();
- float salary=sc.nextFloat();
- Employee e1=new Employee(id,name,salary);
- e.setEmployee(e1);
- }
- if(ch==2)
- {
- System.out.println(e.getEmployee());
- }
- System.out.println("enter 1 to continue");
- int ch1=sc.nextInt();
- if(ch1!=1)
- System.exit(0);
- }
- }
- }
- --------------------------------------
- package newP;
- import java.util.*;
- import java.rmi.*;
- import java.rmi.server.*;
- import java.util.*;
- public class EmployeeImpl extends UnicastRemoteObject implements Employee1
- {
- static ArrayList<Employee> list=new ArrayList<>();
- static
- {
- Employee e1 = new Employee(101,"jack",12000);
- Employee e2 = new Employee(102,"ram",15000);
- list.add(e1);
- list.add(e2);
- }
- protected EmployeeImpl() throws RemoteException {
- super();
- // TODO Auto-generated constructor stub
- }
- public void setEmployee(Employee e)
- {
- list.add(e);
- }
- public List<Employee> getEmployee()
- {
- return list;
- }
- }
- -----------------------------------------
- package newP;
- import java.rmi.registry.*;
- import java.rmi.*;
- import java.rmi.server.*;
- import java.util.*;
- public class EmployeeServer
- {
- public static void main(String args[])throws Exception
- {
- Employee1 m=new EmployeeImpl();
- Registry reg = LocateRegistry.createRegistry(3333);
- reg.rebind("service",m);
- System.out.println("server is ready");
- }
- }
- ques3-------------------------------------
- package Question3;
- public class Employee implements java.io.Serializable
- {
- private int employeeId;
- private String name;
- float salary;
- public Employee(int employeeId,String name,float salary)
- {
- this.employeeId=employeeId;
- this.name=name;
- this.salary=salary;
- }
- public String toString()
- {
- return employeeId+" "+name+" "+salary;
- }
- }
- ---------------------------------------------
- package Question3;
- import java.rmi.*;
- import java.util.*;
- interface Employee1 extends Remote
- {
- public List<Employee> getEmployee() throws Exception ;
- public void setEmployee(int id , String name,float salary) throws Exception ;
- }
- ------------------------------------------------
- package Question3;
- import java.rmi.registry.*;
- import java.rmi.*;
- import java.rmi.server.*;
- import java.util.*;
- class EmployeeClient
- {
- public static void main(String args[]) throws Exception
- {
- int ch;
- // ArrayList<Employee> list=new ArrayList<>();
- Employee1 m = (Employee1)Naming.lookup("rmi://localhost:2222/service");
- Scanner sc = new Scanner(System.in);
- EmployeeImpl e =new EmployeeImpl();
- while(true)
- {
- System.out.println("1.add \n 2.show");
- ch=sc.nextInt();
- if(ch==1)
- {
- System.out.println("Enter id , name ,salary");
- int id=sc.nextInt();
- String name=sc.next();
- float salary=sc.nextFloat();
- e.setEmployee(id,name,salary);
- }
- if(ch==2)
- {
- System.out.println(e.getEmployee());
- }
- System.out.println("enter 1 to continue");
- int ch1=sc.nextInt();
- if(ch1!=1)
- System.exit(0);
- }
- }
- }
- ---------------------------------------------------
- package Question3;
- import java.util.*;
- import java.rmi.*;
- import java.rmi.server.*;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.Statement;
- import java.util.*;
- public class EmployeeImpl extends UnicastRemoteObject implements Employee1
- {
- static ArrayList<Employee> list=new ArrayList<>();
- static Connection con=null;
- static Statement st=null;
- static ResultSet rs=null;
- static
- {
- Employee e1 = new Employee(101,"jack",12000);
- Employee e2 = new Employee(102,"ram",15000);
- list.add(e1);
- list.add(e2);
- }
- protected EmployeeImpl() throws RemoteException {
- super();
- // TODO Auto-generated constructor stub
- }
- public void setEmployee(int id,String name,float salary)
- {
- try
- {
- Class.forName("oracle.jdbc.driver.OracleDriver");
- con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","hr","hr");
- st=con.createStatement();
- st.execute("insert into employee values("+id+",'"+name+"',"+salary+")");
- System.out.println("inserted");
- }catch(Exception e){System.out.println(e);}
- }
- public List<Employee> getEmployee()
- {
- try
- {
- Class.forName("oracle.jdbc.driver.OracleDriver");
- con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","hr","hr");
- st=con.createStatement();
- rs=st.executeQuery("select * from employee");
- while(rs.next())
- {
- Employee e2 =new Employee(rs.getInt(1),rs.getString(2),rs.getFloat(3));
- list.add(e2);
- }
- }catch(Exception e){ System.out.println(e);}
- return list;
- }
- }
- -----------------------------------------------------------
- package Question3;
- import java.rmi.registry.*;
- import java.rmi.*;
- import java.rmi.server.*;
- import java.util.*;
- public class EmployeeServer
- {
- public static void main(String args[])throws Exception
- {
- Employee1 m=new EmployeeImpl();
- Registry reg = LocateRegistry.createRegistry(2222);
- reg.rebind("service",m);
- System.out.println("server is ready");
- }
- }
Add Comment
Please, Sign In to add comment