java - Using PrepareCall method to pass a parm to a function and to return a count Value -


i wrote function in oracle, takes parm , return count. stored procedure's return type number. call function using preparecall method in java as,

public static int checkpreviousload(int id) {      int countprev = 0;      //here run function existing count of loaded id.         try {          callablestatement proc_stmt = connection.preparecall(" {? = call f_chk_previousload(?)}");          proc_stmt.setlong(1, id);          // register type of return value             proc_stmt.registeroutparameter(1, oracletypes.number);          // execute , retrieve returned value.             proc_stmt.execute();          resultset rs = (resultset) proc_stmt.getobject(1);          rs.next();          countprev = rs.getint(1);          system.out.println("the count is: "+countprev);          rs.close();          proc_stmt.close();      } catch(sqlexception e) {          string temp = e.getmessage();          system.out                  .println("error: sql exception when executing f_chk_previousload \n");          system.err.println("error message is: " + temp);          system.err.println("sqlstate: " + e.getsqlstate());      }       return countprev;  }` 

this throwing sqlexception.

error message this: error: sql exception when executing f_chk_previousload

error message is: missing in or out parameter @ index:: 2 sqlstate: null

please tell me went wrong. thanks.

  1. the error you're receiving because have commented out necessary registeroutparameter() method ofcallablestatementinterface , registers output parameter corresponding type.

  2. also, change input parameter 2(as argument number 2 in prepared statement).

and, please don't call stored procedure function.

perform following changes before storing results in resultset :-

callablestatement proc_stmt = connection.preparecall(" {? = call f_chk_previousload(?)}");      proc_stmt.registeroutparameter(1, oracletypes.number); proc_stmt.setlong(2, id);  proc_stmt.execute(); //  ... succeeding code 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -