ReadyAPI 'semantic analysis' error. I have stored my script libraries in bin folder and I am calling the getBuildingInfo method from the groovy test script of ReadyAPI. Most of the time this method works fine but once in a while I get this error. I want to find out what the exact issue and fix the root cause. I tested the code in eclipse and it works perfectly fine.

ERROR:BUG! exception in phase 'semantic analysis' in source unit 'Script15.groovy' The lookup for PropertiesQuery caused a failed compilaton. There should not have been any compilation from this call. BUG! exception in phase 'semantic analysis' in source unit 'Script15.groovy' The lookup for PropertiesQuery caused a failed compilaton. There should not have been any compilation from this call.

14: Apparent variable 'Database' was found in a static scope but doesn't refer to a local variable, static field or class. Possible causes: You attempted to reference a variable in the binding or an instance variable from a static context. You misspelled a classname or statically imported field. Please check the spelling. You attempted to use a method 'Database' but left out brackets in a place not allowed by the grammar. @ line 14, column 17. def dbConn = Database.getDbConnection(env);

public class Database {

public static Connection getDbConnection (String env){

    Connection conn = null;
    Class.forName("com.mysql.jdbc.Driver")

    switch (env){
        case "TEST":
            conn = DriverManager.getConnection("a","b","c")
            break;
        case "DEV":
            conn = DriverManager.getConnection("a","b","d")
            break;
    }

    return conn;
}

public static void closeDbConnection(Connection conn) {

    conn.close();
}
}  


class PropertiesQuery {
    public static String getBuildingInfo(String env, String id, int row ){
        String result = "111";


        def query = "SELECT col1, col2 FROM tabl1 WHERE id = 1"

        def dbConn =  Database.getDbConnection(env);
        def stmt = dbConn.createStatement()
        def rs = stmt.executeQuery(query);

        while(rs.absolute(row)){
            rs.getString("col1")
            rs.getString("col2")

            result = rs.getString("col1") +"/"+rs.getString("col2")
            return result;
        }
    }   
}
1

There are 1 answers

1
Chris Adams On

I have my own Groovy script for returning a SQL connection. Instead of naming the driver, I use the Groovy SQL package....

Oh, there is a gotcha with connecting to databases that I noticed on my machine. Not sure if it is a wider problem, but I have it and have mentioned it elsewhere on here. When I launch SoapUI, I cannot run a test that uses a db connection as it fails. What I have to do is got to the environments screen, select one of my connections and click the 'Test Connection' button. After that, I can run any tests. It is bizarre, but it seems on my machine that clicking test connection simply blows the air out of the pipe...

import groovy.sql.Sql

class jdbcConnections {

jdbcConnections() {

}

def getJdbcConnection(conDetails, log) {

    def connString = conDetails.getConnectionString()
    def url = 'jdbc:oracle:thin:' + connString.substring(connString.indexOf('@'),connString.size());
    def userName = connString.replace('jdbc:oracle:thin:', '');
    userName = userName.substring(0,userName.indexOf('/'));
    def password = connString.substring(connString.indexOf('/') + 1,connString.indexOf('@'));

    log.info('      Connecting to database ' + conDetails.getName() + '.  Using account ' + userName + ' at URL ' + url );

    return Sql.newInstance(url, userName, password, conDetails.getDriver());

}

def getJdbcConnection(conDetails)
{
    def connString = conDetails.getConnectionString()
    def url = 'jdbc:oracle:thin:' + connString.substring(connString.indexOf('@'),connString.size());
    def userName = connString.replace('jdbc:oracle:thin:', '');
    userName = userName.substring(0,userName.indexOf('/'));
    def password = connString.substring(connString.indexOf('/') + 1,connString.indexOf('@'));

    return Sql.newInstance(url, userName, password, conDetails.getDriver());
}

}

The connection details I pass in are from the Environments/JDBC connections screen.