java - store arraylist in oracle database -


this code storing arraylist in database facing problem first element of arraylist stored in database. pls help

  int invoice_no,bookno;   static arraylist<integer> reference=new arraylist<>();   static arraylist<integer> quantity2 = new arraylist<>();     public void abc1()   {        try     {         system.out.println("hello");         class.forname("oracle.jdbc.driver.oracledriver");         connection connection=drivermanager.getconnection("jdbc:oracle:thin:@localhost:1521:xe","system","anchit");         statement statement=connection.createstatement();         resultset r1=statement.executequery("select max(invoice_no) invoice_detail");          int a=1;         while(r1.next())         {              a=r1.getint(1);             system.out.println(r1.getint(1));         }          system.out.println("a="+a);         invoice_no=a+1;         if(invoice_no%50==0)             bookno=(invoice_no/50);         else             bookno=(invoice_no/50)+1;          system.out.println(invoice_no+","+bookno);         system.out.println(reference);          for(int i=0;i<reference.size();i++)         {             class.forname("oracle.jdbc.driver.oracledriver");         connection connection1=drivermanager.getconnection("jdbc:oracle:thin:@localhost:1521:xe","system","anc123hit");         statement statement1=connection1.createstatement();              //int b=             system.out.println(reference.get(i));             //int c=quantity2.get(i);              resultset r=statement1.executequery("insert invoice_detail values("+invoice_no+","+bookno+","                     +reference.get(i)+","+quantity2.get(i)+", to_char(sysdate,'dd-mon-yy'),'anchit','abcd')");              r.next();             connection1.close();         }         connection.close();     }     catch(exception e)     {}   } 

this code storing arraylist in database facing problem first element of arraylist stored in database. pls help

this behavior comes when try use .executequery() on dml (insert, update, delete) operation, should use .executeupdate() instead.

 statement statement1=connection1.createstatement();              //int b=     system.out.println(reference.get(i));             //int c=quantity2.get(i);              //resultset r=;     statement1.executeupdate("insert invoice_detail values("+invoice_no+","+bookno+","                     +reference.get(i)+","+quantity2.get(i)+", to_char(sysdate,'dd-mon-yy'),'anchit','abcd')");              //r.next(); 

usually compiler thrown error query doesn't return resultset when use .executequery on dml


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -