Note that there are some explanatory texts on larger screens.

plurals
  1. PO PreparedStatement error
    primarykey
    data
    text
    <p>I have two select statements and make 'union all' for these two statements. Then, I use the PreparedStatement and when I setString to this preparedStatement, it shows <strong>"java.sql.SQLException: Missing IN or OUT parameter at index:: 2".</strong> </p> <p>After I toured around google, some people say that for each "?" in sql statment, I should write setString. For my situation, I have two select statments so I have two "?" but I "union all", so I'm not sure whether it is assumed that one "?" or two "?". But when I tried to write two setString like <strong>preparedStatement.setString(1,ApplicationNo); preparedStatement.setString(2,ApplicationNo);</strong> , it shows <strong>"ORA-00918: column ambiguously defined".</strong></p> <p>I have no idea how to solve this problem.</p> <p>my union select statment is </p> <pre><code>query.append("select TO_CHAR(TRUNC(SYSDATE),'DD MONTH,YYYY'),a.appl_no,a.assigned_to,b.co_name,b.co_name2,a.credit_acct_no,a.credit_bank_no,a.credit_branch_no,a.service_id "); query.append("from newappl a, newappl_hq b where b.appl_no = a.appl_no and a.appl_no=(select appl_no from newappl where appl_no=?) and rownum=1 and credit_status = 'CRPEND'"); query.append(" union all "); query.append("select TO_CHAR(TRUNC(SYSDATE),'DD MONTH,YYYY'),a.appl_no,a.assigned_to,c.trading_name co_name, ' ' co_name2, d.bank_acct_no credit_acct_no, d.bank_no credit_bank_no, d.bank_branch_no credit_branch_no,a.service_id "); query.append("from newappl a,newappl_hq b, newappl_ret c, newappl_ret_bank d where b.appl_no = a.appl_no or a.appl_no = c.appl_no and c.ret_id= d.ret_id and a.appl_no=(select appl_no from newappl_ret where appl_no=?) and rownum=1 and credit_status = 'CRPEND'");* </code></pre> <p>setString is <strong>preparedStatement.setString(1,ApplicationNo);</strong></p> <p>When I searched for setString example, there are two different parameters if there are two setString like </p> <pre><code>preparedStatement.setString(1,ApplicationNo); preparedStatement.setString(2,LoginID); </code></pre> <p>But I need ApplicationNo for both select statments.</p>
    singulars
    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.
    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