-1

jdbcを使用してJavaで複数のクエリを使用する方法

1.メソッド内の既存のクエリを削除せずに、メソッド内で以下のクエリを使用する
方法

  1. Insert into item_details(stock_name,temple,quantity) SELECT a.stock_name, a.temple, SUM(Case when Type='purchase' then quantity else
    (quantity*-1) End) AS quantity FROM purchase_details a GROUP BY a.stock_name,お寺


       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 = ? where                 
     temple=? and 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;
    
        } 
    
4

1 に答える 1