java - Error on running multiple select query apache derby -


i not able run code below multiple select query. able run queries below individually want run , store results in arraylist. error java.sql.sqlexception: resultset not open. operation 'next' not permitted. verify autocommit off.

any advice? or there better way this? thanks

public arraylist<string> gettotalcountbasicqueries() {          arraylist<string> totalcount = new arraylist();             statement stmt = null;              stmt = conn.createstatement();             conn.setautocommit(false);              try {                  string q1 = "select count query";                 string q2 = "select count query2";                 string q3 = "select count query3 ";                  resultset rs = stmt.executequery(q1);                 resultset rs2 = stmt.executequery(q2);                 resultset rs3 = stmt.executequery(q3);                  while (rs.next()) {                     totalbasiccount.add(rs.getstring(1));                 }                  while (rs2.next()) {                     totalcount.add(rs2.getstring(1));                 }                 while (rs3.next()) {                     totalcount.add(rs3.getstring(1));                 }                   rs.close();                 rs2.close();                 rs3.close();                 stmt.close();             } catch (throwable e) {                 system.out.println("table fetch failed or result data failed");             } {                 if (stmt != null) {                     try {                         stmt.close();                         system.out.println("could not close query");                     } catch (sqlexception ex) {                         system.out.println("could not close query");                     }                 }                  return totalbasiccount;              }         }     } 

see javadoc resultset :

a resultset object automatically closed when statement object generated closed, re-executed, or used retrieve next result sequence of multiple results.

you can't have multiple resultset open unique statement, per spec. however, jdbc driver allow this

try :

resultset rs = stmt.executequery(q1); while (rs.next()) {    totalbasiccount.add(rs.getstring(1)); } resultset rs2 = stmt.executequery(q2); while (rs2.next()) {    totalcount.add(rs2.getstring(1)); } resultset rs3 = stmt.executequery(q3); while (rs3.next()) {    totalcount.add(rs3.getstring(1)); } 

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 -