Error on database testing: communications link failure

Forget completely about this above mentioned, much too cumbersome Keywords file! All you need is the groovy.sql.sql class and only one Keyword routine to build the desired SQL instance, like this one:

package general

import com.kms.katalon.core.annotation.Keyword
import groovy.sql.Sql
public class DBUtils {
  @Keyword
  def getSQLInstance(String dbSystem, String dbServer, String dbPort, String dbName, String dbUsername, String dbPassword) {
    String connectionString
    String serverDriver
    if (dbSystem == 'mysql') {
      connectionString = 'jdbc:' + dbSystem + '://' + dbServer + (dbPort ? (':' + dbPort) : '') + '/' + dbName
      serverDriver = 'com.mysql.jdbc.Driver'
    }
    else if (dbSystem == 'sqlserver') {
      connectionString = 'jdbc:' + dbSystem + '://' + dbServer + (dbPort ? (':' + dbPort) : '') + ';databaseName=' + dbName
      serverDriver = 'com.microsoft.sqlserver.jdbc.SQLServerDriver'
    }
    else if (dbSystem == 'hsqldb:mem') {
      connectionString = 'jdbc:' + dbSystem + ':' + dbName
      serverDriver = 'org.hsqldb.jdbcDriver'
    }/*    else if (dbSystem == 'hsqldb:db_xyz') {      connectionString = 'jdbc:' + dbSystem + 'complete/the/DB-specific/part'      serverDriver = 'add.the.DB-specific.driver'
    }*/    def Sql sql = Sql.newInstance(connectionString, dbUsername, dbPassword, serverDriver)
    return sql
  }
}

This is probably the grooviest way to really use the advantages of Groovy. And it is completely sufficient not to have to deal with the peculiarities of ResultSet and the cumbersome necessity of pushing its pointer forward within the TestCase. Because this groovy.sql.Sql class brings its own groovish methods to process the result sets as maps or lists:

def sql = CustomKeywords.'general.DBUtils.getSQLInstance'(dbSystem, dbServer, dbPort, dbName, dbUsername, dbPassword)
sql.eachRow('SELECT * FROM table') { row ->
  println row
}sql.close()

Look here for more details.