加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

SoapUI Pro Groovy!错误:BUG!源中的“语义分析”中的异常类名

发布时间:2020-12-14 16:29:16 所属栏目:大数据 来源:网络整理
导读:ReadyAPI’语义分析’错误.我已经将我的脚本库存储在bin文件夹中,并且我正在从ReadyAPI的groovy测试脚本中调用getBuildingInfo方法.大多数时候这种方法工作正常,但有一段时间我得到了这个错误.我想找出确切的问题并找出根本原因. 我在 eclipse中测试了代码,
ReadyAPI’语义分析’错误.我已经将我的脚本库存储在bin文件夹中,并且我正在从ReadyAPI的groovy测试脚本中调用getBuildingInfo方法.大多数时候这种方法工作正常,但有一段时间我得到了这个错误.我想找出确切的问题并找出根本原因.
我在 eclipse中测试了代码,它工作得非常好.

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","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;
        }
    }   
}

解决方法

我有自己的Groovy脚本用于返回SQL连接.我使用Groovy SQL包而不是命名驱动程序….

哦,我在机器上注意到连接到数据库的问题.不确定这是否是一个更广泛的问题,但我已经拥有并在此处的其他地方提到过它.当我启动SoapUI时,我无法运行使用数据库连接的测试,因为它失败了.我要做的就是进入环境屏幕,选择我的一个连接,然后单击“测试连接”按钮.之后,我可以进行任何测试.这很奇怪,但似乎在我的机器上点击测试连接只是将空气吹出管道……

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.indexOf('@'));

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

}

我传入的连接详细信息来自Environments / JDBC connections屏幕.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读