Note that there are some explanatory texts on larger screens.

plurals
  1. POWhere is the bug in this code?
    primarykey
    data
    text
    <p>In the following code when if condition fails i.e when else block is reached the procedure runs successfully else throws Closed Statement Exception:</p> <pre><code> public synchronized void create(Map formMap) throws SQLException, Exception { CallableStatement callStmt=null; try { String sql= "BEGIN UP_I_51(?, ?, ?, ?, ?, ?, ?, ?, ?); END;"; callStmt=getConnection().prepareCall(sql); callStmt.setString(1,formMap.get("periodFrom").toString()); callStmt.setString(2, formMap.get("periodTo").toString()); String srcType=formMap.get("srcType").toString(); callStmt.setString(3, srcType); callStmt.setString(4, formMap.get("collabIdMod").toString()); callStmt.setString(5, formMap.get("name").toString()); callStmt.setString(6, formMap.get("address").toString()); callStmt.setString(7, " "); String parCollabId=formMap.get("pCollabId").toString(); if(StringUtils.exists(parCollabId)) { callStmt.setString(8, parCollabId); String parSrcType=getParentSrcType(srcType); callStmt.setString(9, parSrcType); } else { callStmt.setString(8, " "); callStmt.setString(9, " "); } callStmt.executeUpdate(); } finally { callStmt.close(); } } </code></pre> <p>I replaced the code with below code and it is working now. I have used conditions when setting strings before but don't know why exception comes now.</p> <p>I still don't understand why this exception comes. Could anyone find it?</p> <pre><code> public synchronized void create(Map formMap) throws SQLException, Exception { CallableStatement callStmt=null; String srcType=formMap.get("srcType").toString(); String parCollabId=formMap.get("pCollabId").toString(); String parSrcType=getParentSrcType(srcType); try { srcType=formMap.get("srcType").toString(); parCollabId=formMap.get("pCollabId").toString(); parSrcType=getParentSrcType(srcType); parCollabId = StringUtils.exists(parCollabId) ? parCollabId : " "; parSrcType = StringUtils.exists(parCollabId) ? parSrcType : " "; String sql= "{ call UP_I_51(?, ?, ?, ?, ?, ?, ?, ?, ?) }"; callStmt=getConnection().prepareCall(sql); callStmt.setString(1,formMap.get("periodFrom").toString()); callStmt.setString(2, formMap.get("periodTo").toString()); callStmt.setString(3, srcType); callStmt.setString(4, formMap.get("collabIdMod").toString()); callStmt.setString(5, formMap.get("name").toString()); callStmt.setString(6, formMap.get("address").toString()); callStmt.setString(7, " "); callStmt.setString(8, parCollabId); callStmt.setString(9, parSrcType); callStmt.executeUpdate(); }catch(Exception e) { e.printStackTrace(); throw e; } finally { callStmt.close(); } } </code></pre>
    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.
 

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