SoapUI Pro Groovy!错误:BUG!源代码中的阶段'语义分析'异常查找类名导致编译失败
ReadyAPI'语义分析'错误。我已将脚本库存储在bin文件夹中,并且正在从ReadyAPI的groovy测试脚本调用getBuildingInfo
方法。大多数时候这种方法工作正常,但偶尔我会得到这个错误。我想找出确切的问题并解决根本原因。 我在eclipse中测试了代码,它工作得很好。SoapUI Pro Groovy!错误:BUG!源代码中的阶段'语义分析'异常查找类名导致编译失败
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;
}
}
}
我有返回SQL连接我自己的Groovy脚本。我不使用命名驱动程序,而是使用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连接屏幕。
谢谢。我会检查这个,如果这个工作得到回报。我也提出了SmartBear的问题。他们也在研究这一点。现在我决定使用ReadyAPI的内置JDBC连接。 – ktmrocks
几件事情。 1.查询语句不以双引号结尾。 2.'getDBConnection'方法中使用了'env'? – Rao
两个类位于同一个脚本中?你如何加载/调用getBuildingInfo方法? – daggett
@Rao对不起,查询中使用env变量时丢失的双引号和getDBConnection中env变量的使用是我的错字。我纠正了这一点。 – ktmrocks