java - Compare two vector -


i have 2 vector below;

private vector<vector<object>> vector1 = new vector<vector<object>>(); private vector<vector<object>> vector2 = new vector<vector<object>>(); 

some methods fill above vectors , created vectors are;

vector1

[1000, 0, 100100, 1] [1000, 1, 100100, 1] [1000, 2, 100100, 1] [1000, 3, 100100, 1] 

vector 2

[1000, 0, ppp, yyy] [1000, 1, zzz, xxx] 

as can see vector 2 less 2 row. vector's 0th , 1st columns important me. use them in sql query. need delete vector 1 releated columns db when rows not in vector 2.

my code is:

for(int =0; != vector1.size(); i++){         if (i>vector2.size()){             system.out.println("detected");             try{              resultset rs;              statement stmt;              resultsetmetadata rsmtd;              string query = "use dbst\n" +              "delete mtable   me='"+vector1.elementat(i).elementat(0).tostring()+"' , p='"+vector1.elementat(i).elementat(1).tostring()+"'";              class.forname("com.microsoft.sqlserver.jdbc.sqlserverdriver");              string connectionurl = "jdbc:sqlserver://192.168.130.100;" + "databasename=dbst;" + "user=" + "user1" + ";" + "password=" + "user1pass" + ";";               connection con = drivermanager.getconnection(connectionurl);              stmt = con.createstatement();              rs = stmt.executequery(query);             }             catch(sqlexception se){             se.printstacktrace();             }             catch(exception e){             e.printstacktrace();             }         }         else{            system.out.println(vector1.elementat(i).elementat(0).tostring()+vector1.elementat(i).elementat(1).tostring());         }      } 

when run code nothing happened. surplus rows (2nd , 3rd row of vector 1) not deleted db. come else statement , print desired format of current vector1 row.

how can handle this?

thanks

as far comparison goes, can following compare 1st , 2nd entries in each vector, , toss out vector not found db.

list<arraylist<integer>> vector1 = new arraylist<arraylist<integer>>(); list<arraylist<integer>> vector2 = new arraylist<arraylist<integer>>();  arraylist<integer> tmp = new arraylist<integer>(); tmp.add(1000); tmp.add(0); tmp.add(100100); tmp.add(1); vector1.add(tmp); tmp = new arraylist<integer>(); tmp.add(1000); tmp.add(1); tmp.add(100100); tmp.add(1); vector1.add(tmp); tmp = new arraylist<integer>(); tmp.add(1002); tmp.add(2); tmp.add(100100); tmp.add(1); vector1.add(tmp);  tmp = new arraylist<integer>(); tmp.add(1000); tmp.add(0); tmp.add(100102); tmp.add(2); vector2.add(tmp); tmp = new arraylist<integer>(); tmp.add(1000); tmp.add(1); tmp.add(100100); tmp.add(1); vector2.add(tmp);  system.out.println(vector1); system.out.println(vector2);  integer[] vec3 = new integer[2]; integer[] vec4 = new integer[2]; boolean flag = false;  (arraylist<integer> vec1tmp : vector1) {     flag = false;     vec3[0] = vec1tmp.get(0);     vec3[1] = vec1tmp.get(1);      (arraylist<integer> vec2tmp : vector2) {         vec4[0] = vec2tmp.get(0);         vec4[1] = vec2tmp.get(1);          if ( arrays.equals(vec3, vec4) ) {             flag = true;             break;         }      }      if ( !flag ) {         // deletion here         system.out.println(vec1tmp);     } } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -