Can I execute a long multi-line SQL query?

I have .sql file with a very long query, around 1000 lines. Does there exist a way to execute this entire query in a database in katalon? We can do so for a query that is a single line, and which is stored as a string. For example, we store such a query as follows:

Connection conn1 = DriverManager.getConnection("DB connection info here");
String sqlStrSelect3 = "Query line goes here'";

But how do we do it if its 1000 lines long? All we can think of is to convert this query into 1000 seperate strings in a row, which would work, but is highly painful. For example, can we just run a .sql file itself from Katalon or copy and paste the 1000 lines into a Keyword or a Package or Data File?

I tried creating a “Database Data” Data File, but when I tried to “Fetch the Data” I received the error “Unable to fetch data from database.” This error message makes sense because the query is not intended to access data from the database table, but actually inserts data into it. So I’m not sure what to do in this case.



Great question. I’ve been considering doing something similar inside @BeforeTestSuite with a corresponding cleanup in @AfterTestSuite.

I’m guessing we could serialize a file into a string and pass it to executeQuery… but I haven’t tried it yet.

I posted this over two years. Has this functionality been implemented?

For example, I have a .SQL file. or a .TXT file with the equivalent SQL code inside of it. Can either be directly executed on a database without manually inputted the SQL string in Katalon?

@ThanhTo @duyluong

there are various methods available to read the content of a file in java/groovy.

I think the most suitable in this case is .text , e.g:

query = new File('./resources/sql_query.txt').text

This will create a string from the file content (i used same method for json schema validation)

you can read about other available methods here:

1 Like

I think the way to do this is like @bionel showed, read the content of the file into a string and then use the provided API to execute that string.

Thank you. I will try this method.