Domanda

Here is my query i have done using jdbc.webshopProducts is the Map.

StringBuilder queryString=new StringBuilder();
            queryString.append(" select cpm.name,cpm.catalogueprice,cpm.catalogueno ");
            queryString.append(" from customer_product_master cpm ");
            queryString.append(" where cpm.catalogueno in (?) ");
            stmt=con.prepareStatement(queryString.toString());
            stmt.setString(1,StringUtils.join(webshopProducts.keySet(),','));
rs=stmt.executeQuery();
            webshopProductList=new ArrayList<WebshopProductVO>();
            while(rs.next()){
                WebshopProductVO webshopProduct=new WebshopProductVO();
                webshopProduct.setArticleno(rs.getInt("catalogueno"));
                webshopProduct.setName(rs.getString("name"));
                webshopProduct.setPrice(rs.getFloat("catalogueprice"));
                webshopProduct.setQuantity(webshopProducts.get(rs.getInt("catalogueno")));
                webshopProduct.setSum(rs.getFloat("catalogueprice")*webshopProducts.get(rs.getInt("catalogueno")));
                webshopProductList.add(webshopProduct);
            }

I have used StringUtils.join(webshopProducts.keySet(),',') to generate a comma seperated list of integers.The problem i am facing is when there is more than one value in the map only one WebshopProductVO is being added to the webshopProductList even though there are many ones.

È stato utile?

Soluzione

Not sure , which database you are using. But you should be needing the number of ? equals to number of values youar passing.

suppose you have two values for in clause , then it should be :-

where cpm.catalogueno in (?,?)

and you should be setting same number of string.

  stmt.setString(1,"somevalue");
  stmt.setString(2,"somevalue2");

You need to write teh loop on keyset on both statments to append the ? and setting the string parameter

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top