Class implservent extends pnrintfimplbase connection

Info icon This preview shows pages 41–46. Sign up to view the full content.

View Full Document Right Arrow Icon
class implservent extends _pnr_intfImplBase { Connection c; PreparedStatement ps; ResultSet rs; public implservent() 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 getStatus(int id) { try { ps=c.prepareStatement("select * from mypnr where pnr_id=?"); ps.setInt(1,id); rs = ps.executeQuery(); if(rs.next()) return rs.getString(2); else return "~"; } catch(Exception e){} return "~"; } } Server Program: server.java import pnr.*;
Image of page 41

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 42 160317742004 import org.omg.CORBA.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; public class server { public static void main(String args[]) throws Exception { ORB orb =ORB.init(args,null); implservent obj=new implservent(); orb.connect(obj); NamingContext nobj=NamingContextHelper.narrow(orb.resolve_initial_references("NameService")); NameComponent nc=new NameComponent("PNR"," "); NameComponent[] path ={nc}; nobj.rebind(path,obj); java.lang.Object oobj=new java.lang.Object(); synchronized(oobj) { oobj.wait(); } } } Client Program: client.java import pnr.*; import org.omg.CORBA.*; import org.omg.CosNaming.*; import org.omg.CosNaming.NamingContextPackage.*; import java.io.*; import java.util.*; public class client { public static void main(String args[]) throws Exception {
Image of page 42
DS & ADB DCET RAHEEM UNNISA 43 160317742004 BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); ORB orb =ORB.init(args,null); implservent obj=new implservent(); orb.connect(obj); NamingContext nobj=NamingContextHelper.narrow(orb.resolve_initial_references("NameService")); NameComponent nc=new NameComponent("PNR"," "); NameComponent[] path = {nc}; pnr_intf pi=pnr_intfHelper.narrow(nobj.resolve(path)); System.out.print("Enter PNR id:"); String rval=obj.getStatus(Integer.parseInt(br.readLine())); if(!rval.equals("~")) System.out.println("Current Status is: " +rval); else System.out.println("Invalid PNR Number"); } } Execution steps: idlj -fall -oldImpBase pnr_intf.idl start orbd javac *.java java client Output:
Image of page 43

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 44 160317742004 11. Implementation of a middleware component for a bank application to find the balance amount from the Savings Bank Account by using CORBA IDL interface and use JDBC to connect to the database. 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'); Insert into myacc values(1002,’ramu’,’rd’,'222.22'); Executing query: select * from myacc; Saving Table: commit; PROGRAM: IDL Program: bank_intf.idl module bank{ interface bank_intf { long getBalance(in string ac_no); }; };
Image of page 44
DS & ADB DCET RAHEEM UNNISA 45 160317742004 Implementation Program: implservent.java import bank.*; import java.sql.*; class implservent extends _bank_intfImplBase { Connection c; PreparedStatement ps; ResultSet rs; public implservent() throws Exception { Class.forName("oracle.jdbc.driver.OracleDriver"); c=DriverManager.getConnection("jdbc:oracle:thin:@ 192.168.2.60:1521:demo”,”scott”,”ti ger” ); } public int getBalance(String acc_id) { try { ps=c.prepareStatement("select balance from myacc where acc_id=?"); ps.setString(1,acc_id); rs=ps.executeQuery(); if(rs.next())
Image of page 45

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

View Full Document Right Arrow Icon
Image of page 46
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