how to use multiple queries in java using jdbc -


how use multiple queries in java using jdbc

1.how use below query in method without deleting existing query in
method

  1. insert item_details(stock_name,temple,quantity) select a.stock_name, a.temple, sum(case when type='purchase' quantity else
    (quantity*-1) end) quantity purchase_details group a.stock_name, a.temple


       public boolean insertintimationdetails(stockform ofform) {    boolean status=false;    preparedstatement pst=null;    connection conn=null;     try {    system.out.println("inside insertintimationdetails ");      string query=" update purchase_details set intimation_quantity = ?                   temple=? , stock_name=? ";            system.out.println(query);     conn=getconnection();     system.out.println(query);     pst=conn.preparestatement(query);     system.out.println(ofform.getintimationquantity());     pst.setstring(2, ofform.getfortemple());     pst.setstring(3, ofform.getstockname());     pst.setlong(1, ofform.getintimationquantity());                  int rows= pst.executeupdate();     if(rows>0){         status=true;     }         } catch (exception e) {     e.printstacktrace();     }   finally{     try {         if(pst!=null)             pst.close();         if(conn!=null)             conn.close();     } catch (exception e2) {         e2.printstacktrace();     }  }  return status;      }  

you can make 2 sqls atomic using similar below code. guarantees or nothing rule.

public boolean insertintimationdetails(stockform ofform) {     boolean status = false;     preparedstatement pst = null;     connection conn = null;             statement stat = null;      try {         system.out.println("inside insertintimationdetails ");         string query = " update purchase_details set intimation_quantity = ? temple=? , stock_name=? ";         system.out.println(query);         conn = getconnection();         conn.setautocommit(false); // disable auto commit         system.out.println(query);         pst = conn.preparestatement(query);         system.out.println(ofform.getintimationquantity());         pst.setstring(2, ofform.getfortemple());         pst.setstring(3, ofform.getstockname());         pst.setlong(1, ofform.getintimationquantity());          int rows = pst.executeupdate();         if (rows > 0) {             status = true;         }          stat = conn.createstatement();         boolean status2 = stat                 .execute("insert item_details(stock_name,temple,quantity) select a.stock_name, a.temple, sum(case when type='purchase' quantity else (quantity*-1) end) quantity purchase_details group a.stock_name, a.temple");          if (status && status2) {             conn.commit();         } else {             conn.rollback();         }      } catch (exception e) {         e.printstacktrace();         conn.rollback();     } {         try {             if (pst != null)                 pst.close();             if (stat != null)                 stat.close();             if (conn != null)                 conn.close();         } catch (exception e2) {             e2.printstacktrace();         }      }      return status;  } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -