Data connection problem

I was using script that was working well, but after relaunching katalon studio, now it doesn’t work anymore and gives me an error.

using this script: SQLHandler_LMS sql = new SQLHandler_LMS()
in SQLHandler_LMS I have database connection.

I’m not sure about that error message but here is how I’m set up to run sql queries. The runQuery() takes the query as a parameter. I usually save the result to a variable for verification.

package com.generalmethods

import java.sql.DriverManager
import java.sql.ResultSet
import java.sql.Statement

import org.junit.After

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.Driver;
import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.util.KeywordUtil as KeywordUtil

public class RunSQL {

private static Connection connection = null;
@Keyword
def connectDB(){
	String url = "jdbc:sqlserver://servername:1111;integratedSecurity=true;"

	if(connection != null && !connection.isClosed()){
		connection.close()
	}
	connection = DriverManager.getConnection(url)
	return connection
}

@Keyword
def closeDB() {
	if(connection != null && !connection.isClosed()){
		connection.close()
	}
	connection = null
}

@Keyword
def runQuery(String queryString) {
	try {
		this.connectDB()
		Statement stm = connection.createStatement()
		ResultSet result = stm.executeQuery(queryString)
		result.next()
		String output = result.getString(1)
		this.closeDB()
		return output
	}
	catch (Exception e) {
		System.out.println("Exception ocurred while running the SQL statement.");
		KeywordUtil.markFailed('Exception ocurred while running the SQL statement.')
	}
  }
}

I use same script too, I’ve resolved my problem at this moment. Never saw this kind of error, it was saying that the script was too long or something like that at package db_connection, but when I removed it and have written it again, it started working.

What does mean Unresolved compilation problem ? I’m still getting this error :frowning: I don’t know why it is not working anymore, it was working perfectly…

Ahh how many lines of code do you have in your script? I have ran into this issue when my script has too many lines of code. I think groovy has an issue with compiling files too big. To fix it I created keywords for some of the repeatable steps and tried to break up the test into smaller parts.

I made it so too, I have created 2 keywords, one for database connection and second is doing select from database and in test case i only use that :

def k = CustomKeywords.‘db_connection.db_swagger_Deposits_data.getResource’()

println(k)

What about the rest of the script? How many lines of code is the test case? If it is more than ~300 lines then you might have to trim more of the steps.

the rest script is more than 300 lines. it is ~450 lines. Maybe because of that ?

That might be your issue. I would try copying the script and deleting lines of code until the error goes away. I ran into this same issue when I had 500 lines of code. From what I understand its usually bad practice to have that many lines of code in one file. It’s better to break up the test into smaller parts or use more keyword functions.

1 Like

Thanks for help and your attention.

1 Like