Announcement Announcement Module
Collapse
No announcement yet.
Stored Procedure with one input parameters and two output parameters Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Stored Procedure with one input parameters and two output parameters

    Hello,

    I am newbie using spring. can anyone please tell me how to use stored procedures in spring. The stored procedure which i am using has one input paramter and two output paramters. It would be of great help if any of you could post of an example of that kind (with multiple output parameters).

    This is the code which I am trying to modify so that i could use spring instead of plain JDBC.
    -------------------------------------------------------------------
    cstmt = connection.prepareCall("{call ap_TABLE (?, ?, ?)}");
    cstmt.setInt(1, getId());
    cstmt.registerOutParameter(2, Types.INTEGER);
    cstmt.registerOutParameter(3, Types.VARCHAR);

    rs = cstmt.executeQuery();

    -------------------------------------------------------------------


    Thanks in advance

  • #2
    Here is one example of how to do it:

    Code:
        public void callProc() {
            
            Integer id = new Integer(8);
            
            ApTableProc proc = new ApTableProc(dataSource);
            Map result = proc.execute(id);
            
            Number out1 = (Number)result.get("out1");
            String out2 = (String)result.get("out2");
    
        }
    
        public class ApTableProc extends StoredProcedure {
            private static final String PROC_STATEMENT = "AP_TABLE";
    
            public ApTableProc(DataSource dataSource) {
                super(dataSource, PROC_STATEMENT);
                declareParameter(new SqlParameter("id", Types.INTEGER));
                declareParameter(new SqlOutParameter("out1", Types.INTEGER));
                declareParameter(new SqlOutParameter("out2", Types.VARCHAR));
                compile();
            }
    
            public Map execute(Integer id) throws DataAccessException {
                Map inParam = new HashMap(1);
                inParam.put("id", id);
                return super.execute(inParam);
            }
    
        }

    Comment


    • #3
      Thank you Thomas
      It was of great help

      Comment

      Working...
      X