Announcement Announcement Module
Collapse
No announcement yet.
Spring JDBC Storedproc example Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring JDBC Storedproc example

    How to implement the code below using Spring Storedproc? Can't find a more complex example anywhere...

    Thanks,

    Code:
    public Collection getAddresses(String pid) {
            Connection conn = null;
            CallableStatement cstmt = null;
            ResultSet rs = null;
    
            Address address = null;
    
            Collection result = null;
    
            try {
                conn = ds.getConnection();
                cstmt = conn.prepareCall(DATA_ADDR_READ_PROC_NAME);
    
                cstmt.setString(1, pid);
    
                boolean returnedResultSet = cstmt.execute();
    
                result = new ArrayList();
                while (true) {
                    rs = cstmt.getResultSet();
                    if (rs != null) {
          
    
                        while (rs.next()) {
    
                            address = new Address(rs);
                            
                            result.add(address);
    
                        }
                    }
    
             
                    if ((cstmt.getMoreResults() == false) && (cstmt.getUpdateCount() == -1))
                        break;
                }
    
            } catch (SQLException ex) {
                log.error(ex);
                throw new DataAccessException(ex);
            } finally {
                closeResultSet(rs);
                closeStatement(cstmt);
                closeConnection(conn);
            }
    
            return result;
        }

  • #2
    I'm about 100% sure that if you search on the forums for "stored proc" or "stored procedure" you'll find some examples of doing stored procs. I know I saw some from Thomas Risberg, for example.

    Comment

    Working...
    X