Announcement Announcement Module
Collapse
No announcement yet.
Spring SP, returning ResultSet Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring SP, returning ResultSet

    hello all,
    i know this question can be odd, but i have legacty code that calls storedProcedures using callable statement.(not using Spring, usingn plain JDBC returning a ResultSet)

    i was wondering if it was possible to write a Spring StoredProcedure which returns a ResultSet within the Map returned by execute() method..
    so far, i have been unable to do so..
    when i use this code
    Code:
    declareParameter(new SqlReturnResultSet("rs", new ResultSetExtractor() {
                public Object extractData(ResultSet rs) throws SQLException {
                    return rs;
                }}));
    i get back a null ResultSet...
    if i replace that code with this one
    Code:
    declareParameter(new SqlReturnResultSet("rs", new ResultSetExtractor() {
                public Object extractData(ResultSet rs) throws SQLException {
                    Map map = new HashMap();
                    map.put(SPConstants.PARM_ID, rs.getString(1));
                    map.put(SPConstants.PARM_NAM, rs.getObject(2));
                    map.put(SPConstants.PARM_VAL, rs.getObject(3));
                    map.put(SPConstants.DAT_TYP, rs.getObject(4));
                    logger.info("-- Map is:" + map);
                    return map;
                }}));
    i get this exception
    Code:
    declareParameter(new SqlReturnResultSet("rs", new ResultSetExtractor() {
                public Object extractData(ResultSet rs) throws SQLException {
                    Map map = new HashMap();
                    map.put(SPConstants.PARM_ID, rs.getString(1));
                    map.put(SPConstants.PARM_NAM, rs.getObject(2));
                    map.put(SPConstants.PARM_VAL, rs.getObject(3));
                    map.put(SPConstants.DAT_TYP, rs.getObject(4));
                    logger.info("-- Map is:" + map);
                    return map;
                }}));
    the only way to make it work is to use a RowMapper instead..
    could anyone explain me why?

    With kindest regards
    marco

  • #2
    Is it possible to see the stacktrace, it looks like you've posted the code twice instead of the stacktrace.
    Last edited by karldmoore; Aug 27th, 2007, 03:57 PM.

    Comment


    • #3
      hello,
      sorry, here it is

      org.springframework.jdbc.UncategorizedSQLException : CallableStatementCallback; uncategorized SQLException for SQL [{call cdr001dev..sp_bat_get_sql_parms(?)}]; SQL state [JZ0R1]; error code [0]; JZ0R1: Result set is IDLE as you are not currently accessing a row.; nested exception is java.sql.SQLException: JZ0R1: Result set is IDLE as you are not currently accessing a row.
      at org.springframework.jdbc.support.SQLStateSQLExcept ionTranslator.translate(SQLStateSQLExceptionTransl ator.java:121)
      at org.springframework.jdbc.support.SQLErrorCodeSQLEx ceptionTranslator.translate(SQLErrorCodeSQLExcepti onTranslator.java:313)
      at org.springframework.jdbc.core.JdbcTemplate.execute (JdbcTemplate.java:903)
      at org.springframework.jdbc.core.JdbcTemplate.call(Jd bcTemplate.java:936)
      at org.springframework.jdbc.object.StoredProcedure.ex ecute(StoredProcedure.java:113)
      at com.db.sp.SpGetSqlParams.execute(SpGetSqlParams.ja va:49)
      at com.db.sp.SPTest.testCallStoredProcedure(SPTest.ja va:65)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
      at org.springframework.test.ConditionalTestCase.runBa re(ConditionalTestCase.java:69)
      at com.intellij.rt.execution.junit.JUnitStarter.main( JUnitStarter.java:40)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
      at com.intellij.rt.execution.application.AppMain.main (AppMain.java:90)
      Caused by: java.sql.SQLException: JZ0R1: Result set is IDLE as you are not currently accessing a row

      Comment

      Working...
      X