Ds adb dcet raheem 17742004 implementation program

Info icon This preview shows pages 25–31. Sign up to view the full content.

DS & ADB DCET RAHEEM UNNISA 25 160317742004 Implementation program: empimp,java import java.rmi.server.*; import java.sql.*; public class empimp extends UnicastRemoteObject implements empint { Connection c; PreparedStatement ps; ResultSet rs; String res; public empimp() throws Exception { Class.forName ("oracle.jdbc.driver.OracleDriver"); c=DriverManager.getConnection("jdbc:oracle:thin:@ 192.168.2.60:1521:demo”,”scott”,”ti ger” ); } public String getDetails(int id) throws Exception { ps=c.prepareStatement ("select * from myemp where empid=?"); ps.setInt(1,id); rs=ps.executeQuery(); if(rs.next()) { res=rs.getInt(1)+":"+rs.getString(2)+":"+rs.getString(3)+":"+rs.getString(4)+":"+rs.getInt( 5); return res; } else return "~"; } protected void finalize() throws Throwable { c.close(); super.finalize(); } }
Image of page 25

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

DS & ADB DCET RAHEEM UNNISA 26 160317742004 Server program: ser.java import java.rmi.*; public class ser { public static void main(String args[]) throws Exception { empimp obj=new empimp(); Naming.rebind("192.168.1.179",obj); } } Client program: cli.java import java.util.*; import java.io.*; import java.rmi.*; public class cli { public static void main(String args[]) throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String rval; empint obj=(empint) Naming.lookup("192.168.1.179"); System.out.print("enter empid:"); rval=obj.getDetails(Integer.parseInt(br.readLine())); if(!rval.equals("~")) { StringTokenizer st=new StringTokenizer(rval,":"); System.out.println("\t---employee details=---\n"); System.out.println("\tname:"+st.nextToken()); System.out.println("\tage:"+st.nextToken()); System.out.println("\tsalary:"+st.nextToken()); System.out.println("\tservice:"+st.nextToken()); }
Image of page 26
DS & ADB DCET RAHEEM UNNISA 27 160317742004 else System.out.println("\tInvalid ID"); } } Execution steps: javac *.java start rmiregistry start java ser java cli Output:
Image of page 27

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

DS & ADB DCET RAHEEM UNNISA 28 160317742004 7. Implementation of a remote object for a library application having a remote method to list all the books borrowed from the library along with the due date given the roll no of the student. Implement using RMI DATABASE TABLE: Creating Table: create table mtstu(stu_id varchar(20), books varchar(20), issue_dt date, due_dt date); Inserting values into table: insert into mtstu values(1,'e-com','10-aug-08','20-aug-08'); insert into mtstu values(2,'oosd','10-aug-08','20-aug-08'); Executing query: select * from mtstu; Saving Table: commit; PROGRAM: Interface program: stdint.java import java.rmi.*; public interface stdint extends Remote { String getDetails(String id) throws Exception; }
Image of page 28
DS & ADB DCET RAHEEM UNNISA 29 160317742004 Implementation program: stdimp.java import java.rmi.server.*; import java.sql.*; public class stdimp extends UnicastRemoteObject implements stdint { Connection c; PreparedStatement ps; ResultSet rs; String res,temp; public stdimp() throws Exception { Class.forName("oracle.jdbc.driver.OracleDriver"); c=DriverManager.getConnection("jdbc:oracle:thin:@ 192.168.2.60:1521:demo”,”scott”,”ti ger” ); } public String getDetails(String id) throws Exception { ps=c.prepareStatement("select * from mtstu where stu_id=?"); System.out.println(id); ps.setString(1,id); rs=ps.executeQuery(); if(rs.next()) { res=rs.getString(1)+"::"; System.out.println(res); do { temp=rs.getString(2)+":"+rs.getDate(4)+"::"; res+=temp; } while(rs.next()); return res; }
Image of page 29

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

DS & ADB DCET RAHEEM UNNISA 30 160317742004 else return "~"; } protected void finalize() throws Throwable { c.close(); super.finalize(); } } Server program: server.java import java.rmi.*; public class server {
Image of page 30
Image of page 31
This is the end of the preview. Sign up to access the rest of the document.
  • Winter '16
  • zeenath
  • ADB, RAHEEM UNNISA

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern