Forum Discussion

MKV's avatar
MKV
Contributor
7 years ago

How to iterate every row in JDBC resultset

Hi, With ReadyAPI, 2.2.0, I'm trying to validate my response data with the data in DB. There are cases where there could be multiple nodes with customer details. Number of customers will vary for e...
  • Radford's avatar
    7 years ago

    I always process XML data with the XmlSlurper. Here's some sample code of looping through some dummy JDBC test step data:

     

    import groovy.util.XmlSlurper
    
    def jdbcData = '''<Results>
        <ResultSet fetchSize="10">
            <Row rowNumber="1">
                <CUST_NO>aaa</CUST_NO>
            </Row>
            <Row rowNumber="2">
                <CUST_NO>bbb</CUST_NO>
            </Row>
            <Row rowNumber="3">
                <CUST_NO>ccc</CUST_NO>
            </Row>
        </ResultSet>
    </Results>'''
    
    def Results = new XmlSlurper().parseText(jdbcData)
    
    Results.ResultSet.Row.each(){Row ->
    	log.info(Row.CUST_NO)
    }

     

    As an alternative, without using Groovy, you could use an XML Data Source test step (taking its souce as the response of the JDBC test step), paired with a DataSource Loop Test Step will take care of all the looping functionality.