这是我使用jdbc.webshopProducts完成的查询是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);
}
我已经使用StringUtils.join(webshopProducts.keySet(),',')来生成一个逗号分隔的整数列表。我面临的问题是,当地图中有多个值时,只有一个WebshopProductVO正在添加到webshopProductList,即使有很多。
答案 0 :(得分:1)
不确定您使用的是哪个数据库。但你应该需要多少?等于你传递的数值。
假设你有两个in子句的值,那么它应该是: -
where cpm.catalogueno in (?,?)
你应该设置相同数量的字符串。
stmt.setString(1,"somevalue");
stmt.setString(2,"somevalue2");
你需要在两个语句的键集上写一个循环来追加?并设置字符串参数