Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to get result after Inner Join 3 tables
    primarykey
    data
    text
    <p>I have declare a <code>List&lt;Object[]&gt;</code> which returning list of object array, where each array represents a row in result. And index of values are based on your select statement.</p> <pre><code>productList = (List&lt;Object[]&gt;) session.createSQLQuery(" SELECT User.username, User.email, Orders.p_id, Orders.o_id, Product.listed_price " + "FROM Orders " + "INNER JOIN User ON User.u_id = Orders.u_id " + "INNER JOIN Product ON Product.p_id = Orders.p_id " + "WHERE Product.p_id = '"+p_id +"' " + "ORDER BY User.username").list(); </code></pre> <p>I have 3 tables <strong>User, Product and Orders</strong>.</p> <pre><code>USER: -----+-----------+------------+---------+----------+-----------+ u_id | username | password | contact | email | city | ------+-----------+------------+---------+---------+-----------+ PRODUCT: +------+----------+--------------+------+--------------+ | p_id | category | listed_price | qty | description | +------+----------+--------------+------+--------------+ ORDERS: +------+--------+------+------+-----------+ | o_id | date | u_id | p_Id | order_qty | +------+--------+------+------+-----------+ </code></pre> <p>I wants to Inner joins User table with Product along with o_id (from ORDER) in below order:</p> <pre><code>+-----------+-------+------+------+--------------+ | username | email | p_id | o_id | listed_price | +-----------+-------+------+------+--------------+ </code></pre> <p>In my ActionClass/View class i declare <code>public List&lt;Object[]&gt; productList;</code> to access object list from controller class above. </p> <pre><code>public List&lt;Object[]&gt; productList; public String listAllProduct(){ HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST); productList = orderDaoFactory.listProduct(Integer.parseInt( request.getParameter("p_id"))); System.out.println("\t"+productList.get(0).toString()); return SUCCESS; } </code></pre> <p>In my JSP page i'm using this list (array of object) productList as an Iterator tag to iterate all customers who have ordered that product.</p> <pre><code>&lt;s:iterator value="productList"&gt; &lt;tr&gt; &lt;td&gt;&lt;h4&gt;&lt;s:property value="username"/&gt;&lt;/h4&gt;&lt;/td&gt; &lt;td&gt;&lt;h4&gt;&lt;s:property value="email"/&gt;&lt;/h4&gt;&lt;/td&gt; &lt;td&gt;&lt;h4&gt;&lt;s:property value="p_id"/&gt;&lt;/h4&gt;&lt;/td&gt; &lt;td&gt;&lt;h4&gt;&lt;s:property value="o_id"/&gt;&lt;/h4&gt;&lt;/td&gt; &lt;td&gt;&lt;h4&gt;&lt;s:property value="listed_price"/&gt;&lt;/h4&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/s:iterator&gt; </code></pre> <p><strong>Challenges/Issues:</strong> My problem is not to get output successfully even not getting any error after debugging. Empty mind now thinking to use O/R mapping to associate Objects JOIN with others. Please suggest me where i am wrong. Your suggestions appreciable.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload