Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 组合JSP中两个表的数据的结果集,Servlet_Sql_Jsp_Join - Fatal编程技术网

Sql 组合JSP中两个表的数据的结果集,Servlet

Sql 组合JSP中两个表的数据的结果集,Servlet,sql,jsp,join,Sql,Jsp,Join,我有这张桌子 table product(id,name) table component(id,name,quantity) table_product_component(p_id,C_id) 一个产品可以有许多组件,一个组件可以属于许多产品 如何执行联接查询并获得显示产品名称、组件名称和数量的结果集 当我执行sql查询以返回这些数据时,我通常将其存储在ArrayList中,因此在本例中,我创建了itemline的新对象,该对象将存储产品、组件类型。然后我可以将查询结果存

我有这张桌子

   table product(id,name)
   table component(id,name,quantity)
   table_product_component(p_id,C_id)
一个产品可以有许多组件,一个组件可以属于许多产品

如何执行联接查询并获得显示产品名称、组件名称和数量的结果集

当我执行sql查询以返回这些数据时,我通常将其存储在ArrayList中,因此在本例中,我创建了itemline的新对象,该对象将存储产品、组件类型。然后我可以将查询结果存储在ArrayList中。那么,我可以简单地编写逻辑来显示一个通知,如果数量是0之类的

问题是我从来没有使用过视图或关系表,比如table_product_组件(p_id,C_id) 因此,我不确定如何查询数据集以获得我想要的结果

欢迎任何想法、方法、代码、理论来帮助我解决这个问题,我们将不胜感激

我实际上也需要servlet/JSP逻辑


谢谢。

所以我用某种方式解决了这个问题。我在jsp中使用了java

                  <%
            Cart cart = (Cart) session.getAttribute("cart");
            List<LineItem> items = cart.getItems();
            for (LineItem item : items) {
            Product product = item.getProduct();


        %> 

        <tr> 
            <td> 
                <form action="<%=response.encodeURL("DisplayCart")%>"> 
                    <input type="hidden" name="productId"  
                           value="<%=product.getId()%>"> 
                    <input type="text" size=2 name="quantity"  
                           value="<%=item.getQuantity()%>"> 
                    <input type="submit" value="Update"> 
                </form> 
            </td> 
            <td> 
                <%=product.getDescription()%> 
            </td>
            <td><%=product.getPrice()%></td>
            <td> 
                <form action="<%= response.encodeURL("DisplayCart")%>"> 
                    <input type="hidden" name="productId"  
                           value="<%=product.getId()%>"> 
                    <input type="hidden" name="quantity"  
                           value="0"> 
                    <input type="submit" value="RemoveButton"> 
                </form> 
            </td>
        <td>           
       <%
        String p = product.getId();        
        List<String> pcs = PcDb.selectCidFromPc(p);
        for (String temp : pcs) {

        Component component = ComponentDb.selectComponent(temp);
        int c = component.getQuantity(); 
        if(c==0){
        out.println("Product is not in stock at the moment, expect delays");
        }
        }
        %>  
        </td>
        </tr> 

        <% }%>