Hello colleagues!
Have one question, i am trying to get the following data from DB:
i have the keyword for executing the query from database:
def executeQuery_2_result(String queryString) {
Statement stm = connection.createStatement()
ResultSet rs = stm.executeQuery(queryString)
//Move the cursor in the ResultSet table to the first row
rs.next()
//Save the result as a string
String valueFromDatabase = rs.getString(1)
String valueFromDatabase2 = rs.getString(2)
//Print our result from the database as a string to the console
println(valueFromDatabase)
println(valueFromDatabase2)
return [valueFromDatabase2, valueFromDatabase]
but it dont work it only returns the values if there are in one row like this:
could you please help me how can i modify my keyword that he returns the values which i want
in testcase the code is following":
CustomKeywords.'md_db.sql.connectDB'(GlobalVariable.dbname, GlobalVariable.schemename, GlobalVariable.dbport, GlobalVariable.dbuser, GlobalVariable.dbpass)
String loan_amount = CustomKeywords.'md_db.sql.executeQuery_2_rows'('select internal_account from u_transactions where bill_id = '+ invoice_number +' order by id desc;')
CustomKeywords.'md_db.sql.closeDatabaseConnection'()
I think this piece of code is basically retrieving values from the first and the second column of the current data row. Can you write something like this:
def executeQuery_2_result(String queryString) {
Statement stm = connection.createStatement()
ResultSet rs = stm.executeQuery(queryString)
//Move the cursor in the ResultSet table to the first row
rs.next()
//Save the result as a string
String valueFromDatabase = rs.getString(1)
//Move the cursor in the ResultSet table to the second row
rs.next()
// Still get the value from the first column
String valueFromDatabase2 = rs.getString(1)
//Print our result from the database as a string to the console
println(valueFromDatabase)
println(valueFromDatabase2)
return [valueFromDatabase2, valueFromDatabase]
def executeQuery_2_rows(String queryString) {
Statement stm = connection.createStatement()
ResultSet rs = stm.executeQuery(queryString)
//Move the cursor in the ResultSet table to the first row
rs.next()
//Save the result as a string
String valueFromDatabase = rs.getString(1)
rs.next()
String valueFromDatabase2 = rs.getString(1)
//Print our result from the database as a string to the console
println(valueFromDatabase)
println(valueFromDatabase2)
String finalvalue = valueFromDatabase2 +'\n' +valueFromDatabase
return finalvalue
i got two strings summ and then i return this new string