sql - How to save the results of a query on variables for each field on Java? -


i need accomplish following:

1.- save on different variables each field of query result (oracle db).
query result 1 o more rows (5 average).
2.- invoke webservice each row.
4.- wait webservice answer , repeat process.

i think saving result of 1 row , invoke webservice easy problem when query result throws more 1 row.

how can this? arraylist answer?

edit: using following code. how can print arraylist see if connection working? if run get:

com.packagename.somebean@1d251891 com.packagename.somebean@48140564 com.packagename.somebean@58ceff1 


connection con = null; statement stmt = null; resultset rs = null;  list<somebean> v = new arraylist<somebean>();  string query = "select * table rownum between 1 , 3";  try  {   class.forname("oracle.jdbc.driver.oracledriver");       con = drivermanager.getconnection("jdbc:oracle:thin:user/pass@localhost:port:sid");       stmt = con.createstatement();            rs = stmt.executequery(query);    while( rs.next() ){                   somebean n = new somebean();     n.setcolumn1(rs.getint("column1"));     n.setcolumn2(rs.getstring("column2"));     n.setcolumn3(rs.getstring("column3"));     n.setcolumn4(rs.getint("column4"));     n.setcolumn5(rs.getstring("column5"));     n.setcolumn6(rs.getstring("column6"));     n.setcolumn7(rs.getstring("column7"));     ...     v.add(n);            }    for(somebean s : v){     system.out.println(s);   }  } catch (classnotfoundexception e) {       e.printstacktrace(); } catch (sqlexception e) {     e.printstacktrace(); } {     try {         stmt.close();         con.close();     } catch (sqlexception e) {         e.printstacktrace();     } } 

answering question quite difficoult. can give hints.

your startpoint jdbc.

the java database connectivity (jdbc)

the java database connectivity (jdbc) api industry standard database-independent connectivity between java programming language , wide range of databases sql databases , other tabular data sources, such spreadsheets or flat files. jdbc api provides call-level api sql-based database access.

the java database connectivity (jdbc)

once able establish connection db, snippet can answering question.

    // start connection     list<somebean> v = new arraylist<somebean>();     statement st;     try      {         st = conn.createstatement();          resultset rs = st.executequery(sql);                 while( rs.next() ){                               somebean n = new somebean();                 n.setfirstfield(rs.getint("firstfield"));                 n.setsecondfield(rs.getstring("secondfield"));                  ...                 ...                  v.add(n);         }     }      catch (sqlexception e)      {         e.printstacktrace();     }      // close connection 

once have collection of beans, write loop calls webservice 1 time each bean.

    for(somebean s : v){              calltoyouws(s);      } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -