How to execute SQL query within a scenario?

Hi all,

I have a requirement where I am feeding value from sql query to an API and then saving one of the value from the response of API and then writing that variable value into the target DB. I am having a trouble understanding how to write it.

I have written following code so far.
`

private val dbConnectionString = “jdbc:oracle:thin:@…”
private val sqlQuery = “SELECT aaa FROM abc”
private val sqlUserName = “abc”
private val sqlPassword = “12345”

private val dbConnectionString2 = “jdbc:jtds:abcdef…”
private val sqlQuery2 = “INSERT INTO…”
private val sqlUserName2 = “def”
private val sqlPassword2 = “abcdef”

val sqlQueryFeeder: SourceFeederBuilder[Any] = jdbcFeeder(dbConnectionString,
sqlUserName,
sqlPassword,
sqlQuery
)

val sqlQueryFeeder2: SourceFeederBuilder[Any] = jdbcFeeder(dbConnectionString2,
sqlUserName2,
sqlPassword2,
sqlQuery2
)

//assigning base URL to a variable. we define the .baseURL() that will be prepended to all HTTP requests.
val httpProtocol = http.baseUrl(url)

//defining header for our http request. We can have multiple headers if our requests need different headers
val header = Map(
//“User-agent” → “Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0”)
“User-agent” → “Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko”) //-----For Internet Explorer
//“User-agent” → “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36”) //-----For Chrome

object payload{

val pl1 = scenario(“ExtractData”)
.feed(sqlQueryFeeder) //feeding data
.exec(http(“Get_Obj_ID”)
.post("/abcdef/")
.headers(header)
.check(status.is(200))
.body(ElFileBody(“extract.txt”)).check( regex( “(?<=)(.*\n?)(?=)”).saveAs(“Id”))) //saving one variable form the api response
.exec (session => {
val objVal = session(“Id”).as[String].trim) //trying to save the session variable in a variable and need to insert this value in the target table using the sql query specified in th ebeginnig- sqlQuery2 below but not sure how to write that code.
.exec()
`

https://gatling.io/docs/current/extensions

Warning

Those projects are third parties and are not maintained by GatlingCorp core committers. If you run into an issue, please contact their respective owners.