Search code examples
oracle-databasegrailsstored-procedures

Grails call stored procedure with output parameter


how to call an Oracle procedure with paramters in grails, the produre looks like this,

var returntype number; begin IZMST_PKG_SOLO_GENERATE_SQL.pro_get_row_cnt(1,181,:returntype); end;

I have tried to call this procedure but the program encounter an error, you can check the error message as below.

org.apache.commons.dbcp.DelegatingCallableStatement with address:
    "oracle.jdbc.driver.OracleCallableStatementWrapper@52d0d407" is
    closed.. Stacktrace follows: java.sql.SQLException:
    org.apache.commons.dbcp.DelegatingCallableStatement with address:
    "oracle.jdbc.driver.OracleCallableStatementWrapper@52d0d407" is
    closed.     at
    org.apache.commons.dbcp.DelegatingStatement.checkOpen(DelegatingStatement.java:137)
        at
org.apache.commons.dbcp.DelegatingCallableStatement.getObject(DelegatingCallableStatement.java:144)
    at
com.pg.izoom.de.ExtractManagementController$$EO5PWcUR.addExtract(ExtractManagementController.groovy:74)
    at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

pasted a piece of the code

Connection conn = dataSource.getConnection()
            Sql sql = new Sql(conn)
            //int test  = sql.call("",)
            sql.call'BEGIN  IZMST_PKG_SOLO_GENERATE_SQL.pro_get_row_cnt(?,?,?); END;',[1L,qryId,Sql.resultSet(OracleTypes.NUMBER)],{dwells-> 
                println dwells
            }

PS: this problem has been solved, update the description to make this question easier to understand.


Solution

  • If I understood, your return type is number, so your can use directly Sql.NUMERIC.

    sql.call '{call IZMST_PKG_SOLO_GENERATE_SQL.pro_get_row_cnt(?,?,?) }',[1L, qryId, Sql.NUMERIC],{ dwells -> 
      println dwells
    }