Forum Discussion

alibaba82's avatar
alibaba82
Super Contributor
15 years ago

reading datasource (JDBC) values into a groovy script

I have a jdbc datasource which returns some records. I want to read them (some specific column) into a list in groovy. How can I do this?

THanks

Ali

1 Reply

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    Try this code in a groovy script in the DataSource loop:


    //Initialize the empty list if needed
    if(!context.hasProperty('myprop')) context.setProperty('myprop', [])

    //Get the new value
    def row =  context.testRunner.testCase.testSteps['DataSource'].getPropertyValue('dataSourceCol')

    //Append the new value to the existing list of values
    context.setProperty('myprop', context.getProperty('myprop') + row)

    //Print the entire list, so far.
    log.info context.getProperty('myprop')


    Once the loop has run completely you can still access the context property, so if you want to do something with the completed list, then create another groovy script after the loop. Good luck!

    Regards,
    Dain
    eviware support