database - Rmi (two different interfaces) -


i'm doing project on distributed system. want query partitions of table , these distributed systems connected via rmi. project query database partition on pc(localhost) , partition on other pc(ip address). have created 2 interfaces , implementation, 1 containing methods pc, other other machine. on excuetion, i'm getting correct result database localhost no result other machine. i'm adding code below. please me.

this interface 1

public interface if5 extends remote{ public void insert(int r, string name, float c) throws remoteexception; public void up_date(int r,string name) throws remoteexception; public void up_date(int r,float cgpa) throws remoteexception; public void up_date(int r,string name,float cgpa) throws remoteexception; public void delete(int r) throws remoteexception; public arraylist<string> select() throws remoteexception; } 

this implementation 1

public class impl51 extends unicastremoteobject implements if51 {   public impl51() throws remoteexception, sqlexception{      } public connection connes() throws sqlexception {       try {          class.forname("oracle.jdbc.oracledriver");          connection con =   drivermanager.getconnection("jdbc:oracle:thin:@192.168.0.115:1521:orcl","hr","ankita1");          return con;      } catch (classnotfoundexception ex) {          logger.getlogger(impl5.class.getname()).log(level.severe, null, ex);       }       return null; }  @override public arraylist<string> select1() throws remoteexception {     try {          connection ncon = connes();          statement stmt = ncon.createstatement();           arraylist<string> ar = new arraylist<string>();          resultset rs = stmt.executequery("select * student_g");          while(rs.next())          {              string r1 = integer.tostring(rs.getint("rollno"));              string str = rs.getstring("name");              string f1 = float.tostring(rs.getfloat("cgpa"));             ar.add(r1);             ar.add(str);             ar.add(f1);           }          return ar;         } catch (sqlexception ex) {          logger.getlogger(impl5.class.getname()).log(level.severe, null,  ex);          return null;      }    }   } 

this server

public class server5 {     public static void main(string args[]) throws exception     { system.setproperty("java.rmi.server.hostname","192.168.0.174");         try{             impl5 o1 = new impl5();             naming.bind("insert", o1);             system.out.println("object1 registered");            impl5 o2 = new impl5();             naming.bind("update1", o2);             system.out.println("object2 registered");             impl5 o3 = new impl5();             naming.bind("update2", o3);             system.out.println("object3 registered");             impl5 o4 = new impl5();             naming.bind("update3", o4);             system.out.println("object4 registered");             impl5 o5 = new impl5();             naming.bind("delete", o5);             system.out.println("object5 registered");`enter code here`             impl5 o6 = new impl5();             naming.bind("select", o6);             system.out.println("object6 registered");      }     catch(exception e)     {         system.out.println("exception: "+e);     }    } } 

other server same methods bound using other name.

implementation 2

    public class impl5 extends unicastremoteobject implements if5 {       public impl5() throws remoteexception, sqlexception{          }     public connection connes() throws sqlexception     {           try {              class.forname("oracle.jdbc.driver.oracledriver");              connection con = drivermanager.getconnection("jdbc:oracle:thin:@localhost:1521:orcl","hr","hr");              return con;          } catch (classnotfoundexception ex) {              logger.getlogger(impl5.class.getname()).log(level.severe, null, ex);           }           return null;     }     @override     public void insert(int r, string n, float c) throws remoteexception {          try {              connection ncon = connes();              statement stmt = ncon.createstatement();              string query = "insert student_g values("+r+",'"+n+"',"+c+")";              resultset rs = stmt.executequery(query);              system.out.println("insert successful");              stmt.close();             ncon.close();           } catch (sqlexception ex) {               logger.getlogger(impl5.class.getname()).log(level.severe, null, ex);          }     }      @override     public void up_date(int r,string n) throws remoteexception {        try {              connection ncon = connes();              statement stmt = ncon.createstatement();              resultset rs = stmt.executequery("update student_g set name= '"+n+"' rollno ="+r);              system.out.println("update successful");              stmt.close();             ncon.close();           } catch (sqlexception ex) {              logger.getlogger(impl5.class.getname()).log(level.severe, null, ex);          }     }     @override     public void up_date(int r, float c) throws remoteexception {        try {              connection ncon = connes();              statement stmt = ncon.createstatement();              resultset rs = stmt.executequery("update student_g set cgpa="+c+"where rollno ="+r);               system.out.println("update successful");              stmt.close();             ncon.close();           } catch (sqlexception ex) {              logger.getlogger(impl5.class.getname()).log(level.severe, null, ex);          }     }     @override     public void up_date(int r,string n,float c) throws remoteexception {        try {              connection ncon = connes();              statement stmt = ncon.createstatement();              resultset rs = stmt.executequery("update student_g set name= '"+n+"',cgpa="+c+ " rollno ="+r);               system.out.println("update successful");              stmt.close();             ncon.close();           } catch (sqlexception ex) {              logger.getlogger(impl5.class.getname()).log(level.severe, null, ex);          }     }      @override     public void delete(int r) throws remoteexception {        try {              connection ncon = connes();              statement stmt = ncon.createstatement();              resultset rs = stmt.executequery("delete student_g rollno ="+r);               system.out.println("delete successful");              stmt.close();             ncon.close();            } catch (sqlexception ex) {              logger.getlogger(impl5.class.getname()).log(level.severe, null, ex);          }     }      @override     public arraylist<string> select() throws remoteexception {         try {              connection ncon = connes();              statement stmt = ncon.createstatement();               arraylist<string> ar = new arraylist<string>();              resultset rs = stmt.executequery("select * student_g");              while(rs.next())              {                  string r1 = integer.tostring(rs.getint("rollno"));                  string str = rs.getstring("name");                  string f1 = float.tostring(rs.getfloat("cgpa"));                 ar.add(r1);                 ar.add(str);                 ar.add(f1);               }              return ar;             } catch (sqlexception ex) {              logger.getlogger(impl5.class.getname()).log(level.severe, null, ex);              return null;          }       }      } client      public class client5 {      public static void main(string args[]) throws exception{        string msg=null;        string msg1= null;        int count =0; string msg2= null;        scanner sc = new scanner(system.in);        do{          system.out.println("what operation want perform: ");          system.out.println("select 1 insert");          system.out.println("select 2 update");          system.out.println("select 3 delete");          system.out.println("select 4 select");          system.out.println("select 5 select");           int ch = sc.nextint();          switch(ch)          {              case 1:  string s1 = "rmi://localhost/insert";                       if5 x = (if5)naming.lookup(s1);                       do{                           system.out.println("enter values insert: ");                           system.out.println("rollno: ");                           int r = sc.nextint();                           system.out.println("name: ");                           string n = sc.next();                           system.out.println("cgpa: ");                           float c = sc.nextfloat();                           x.insert(r, n, c);                           system.out.println("do want continue??(y/n)");                           msg = sc.next();                        }while(!msg.equalsignorecase("n"));                        system.out.println("insert successful");                   break;              case 2: do{                       system.out.println("what want update? a/s");                      string sel = sc.next();                      if(sel.equalsignorecase("a"))                      {                            string s2 = "rmi://localhost/update3";                            if5 x1 = (if5)naming.lookup(s2);                             do{                           system.out.println("enter values update: ");                           system.out.println("rollno: ");                           int r = sc.nextint();                           system.out.println("name: ");                           string n = sc.next();                           system.out.println("cgpa: ");                           float c = sc.nextfloat();                           x1.up_date(r, n, c);                           system.out.println("do want continue??(y/n)");                           msg = sc.next();                        }while(!msg.equalsignorecase("n"));                      }                     else                      {                          system.out.println("what want update? n/c");                          sel = sc.next();                      if(sel.equalsignorecase("n"))                      {                           string s3 = "rmi://localhost/update1";                            if5 x2 = (if5)naming.lookup(s3);                             do{                           system.out.println("enter values update: ");                           system.out.println("rollno: ");                           int r = sc.nextint();                           system.out.println("name: ");                           string n = sc.next();                           x2.up_date(r, n);                           system.out.println("do want continue??(y/n)");                           msg = sc.next();                        }while(!msg.equalsignorecase("n"));                      }                      if(sel.equalsignorecase("c"))                      {                           string s4 = "rmi://localhost/update2";                            if5 x3 = (if5)naming.lookup(s4);                             do{                           system.out.println("enter values update: ");                           system.out.println("rollno: ");                           int r = sc.nextint();                           system.out.println("cgpa: ");                           string c = sc.next();                           x3.up_date(r, c);                           system.out.println("do want continue??(y/n)");                           msg = sc.next();                        }while(!msg.equalsignorecase("n"));                      }                      }                    system.out.println("do want continue update??(y/n)");                    msg2 = sc.next();                   }while(!msg2.equalsignorecase("n"));                        system.out.println("update successful");              break;              case 3: string s5 = "rmi://localhost/delete";                       if5 x4 = (if5)naming.lookup(s5);                       do{                           system.out.println("enter values insert: ");                           system.out.println("rollno: ");                           int r = sc.nextint();                           x4.delete(r);                           system.out.println("do want continue??(y/n)");                           msg = sc.next();                        }while(!msg.equalsignorecase("n"));                        system.out.println("delete successful");              break;                    case 4: string s6 ="rmi://localhost/select";                       if5 x5 = (if5)naming.lookup(s6);                       arraylist<string> arr= x5.select();                     system.out.println("roll no.\tname\tcgpa");           for(string s:arr)                          {               count++;                            system.out.print("\t"+s);               if(count ==3)                             {                                  count=0;                                   system.out.print("\n");                               }                         }               break;                  case 5: string s7 ="rmi://192.168.0.115/select1";                       if51 x6 = (if51)naming.lookup(s7);                       arraylist<string> ar= x6.select1();                     system.out.println("roll no.\tname\tcgpa");           for(string s:ar)                           {               count++;                            system.out.print("\t"+s);               if(count ==3)                             {                                  count=0;                                   system.out.print("\n");                               }                         }               break;                                        default : system.out.println("enter correct value");          }          system.out.println("do want continue selecting operation??   (y/n)");         msg1 = sc.next();      }while(!msg1.equalsignorecase("n"));        } 

for last case trying access other machine, not result. please me. it's important.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -