Public static void mainstring arg throws exception

Info icon This preview shows pages 30–36. Sign up to view the full content.

View Full Document Right Arrow Icon
public static void main(String arg[]) throws Exception { stdimp obj = new stdimp(); Naming.rebind("192.168.1.179",obj); } } Client program: client.java import java.util.*; import java.io.*; import java.rmi.*; public class client { public static void main(String args[])throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String rval; stdint obj = (stdint)Naming.lookup("192.168.1.179"); System.out.print("Enter Student Id : "); rval=obj.getDetails(br.readLine());
Image of page 30

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

View Full Document Right Arrow Icon
DS & ADB DCET RAHEEM UNNISA 31 160317742004 System.out.println(rval); if(!rval.equals("~")) { StringTokenizer st = new StringTokenizer(rval,"::"); System.out.println("\t---Student Books Details---\n\n"); System.out.println("\tStd_id : "+st.nextToken()); while(st.hasMoreTokens()) { System.out.println("\tBook_Name : "+st.nextToken(":")); System.out.println("\tDue_Dt : "+st.nextToken(":")); System.out.println(" "); } } else System.out.println("\tInvalid Id"); } } Execution Steps: javac *.java start rmiregistry start java server java client Output:
Image of page 31
DS & ADB DCET RAHEEM UNNISA 32 160317742004 8. Implementation of a remote object for a bank application having a remote method to display the balance of an account holder. Implement using RMI DATABASE TABLE: Creating Table: Create table myacc(acc_id varchar(20), name varchar(20), type varchar(20), balance Number(8,2)); Inserting values into table: Insert into myacc values(1001,’raju’,’saving’,'1000.22'); Ins ert into myacc values(1002,’ramu’,’rd’,'222.22'); Executing query: select * from myacc; Saving Table: commit; PROGRAM: Interface program: bankint.java import java.rmi.*; public interface bankint extends Remote { String getDetails(String id) throws Exception; } Implementation program: bankimp.java import java.rmi.server.*;
Image of page 32

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

View Full Document Right Arrow Icon
DS & ADB DCET RAHEEM UNNISA 33 160317742004 import java.sql.*; public class bankimp extends UnicastRemoteObject implements bankint { Connection c; PreparedStatement ps; ResultSet rs; String res,temp; public bankimp() 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 myacc where acc_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(3)+":"+rs.getInt(4)+"::"; res+=temp; } while(rs.next()); return res; } else return "~"; }
Image of page 33
DS & ADB DCET RAHEEM UNNISA 34 160317742004 protected void finalize() throws Throwable { c.close(); super.finalize(); } } Server program: server.java import java.rmi.*; public class server { public static void main(String arg[]) throws Exception { bankimp obj = new bankimp(); Naming.rebind("192.168.1.179",obj); } } Client program: client.java import java.util.*; import java.io.*; import java.rmi.*; public class client { public static void main(String args[])throws Exception { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String rval; bankint obj = (bankint)Naming.lookup("192.168.1.179"); System.out.print("Enter account Id : "); rval=obj.getDetails(br.readLine()); System.out.println(rval); if(!rval.equals("~"))
Image of page 34

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

View Full Document Right Arrow Icon
DS & ADB DCET RAHEEM UNNISA 35 160317742004 { StringTokenizer st = new StringTokenizer(rval,"::"); System.out.println("\t---Bank Details---\n\n"); System.out.println("\tacc_id : "+st.nextToken()); while(st.hasMoreTokens()) { System.out.println("\t account type : "+st.nextToken(":")); System.out.println("\t Balance : "+st.nextToken(":"));
Image of page 35
Image of page 36
This is the end of the preview. Sign up to access the rest of the document.

{[ 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