gpt4 book ai didi

groovy - SoapUI Pro Groovy!源代码中 'semantic analysis' 阶段中的 ERROR :BUG! 异常查找类名导致编译失败

转载 作者:行者123 更新时间:2023-12-04 15:51:59 24 4
gpt4 key购买 nike

ReadyAPI“语义分析”错误。我已经将我的脚本库存储在 bin 文件夹中,我正在调用 getBuildingInfo ReadyAPI 的常规测试脚本中的方法。大多数情况下,此方法工作正常,但偶尔我会收到此错误。我想找出确切的问题并解决根本原因。
我在 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","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;
}
}
}

最佳答案

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

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

导入 groovy.sql.Sql

类 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());
}

}

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

关于groovy - SoapUI Pro Groovy!源代码中 'semantic analysis' 阶段中的 ERROR :BUG! 异常查找类名导致编译失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46206685/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com