DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Spring Microservice Tip: Abstracting the Database Hostname With Environment Variable
  • Top Automation Testing Tools for 2024
  • Spring Microservice Application Resilience: The Role of @Transactional in Preventing Connection Leaks
  • Building and Integrating REST APIs With AWS RDS Databases: A Node.js Example

Trending

  • Unmasking Entity-Based Data Masking: Best Practices 2025
  • Scaling DevOps With NGINX Caching: Reducing Latency and Backend Load
  • Accelerating Debugging in Integration Testing: An Efficient Search-Based Workflow for Impact Localization
  • Immutable Secrets Management: A Zero-Trust Approach to Sensitive Data in Containers
  1. DZone
  2. Data Engineering
  3. Data
  4. How to Perform Database Testing Using Katalon Studio

How to Perform Database Testing Using Katalon Studio

Get sample code demonstrating how to establish a database connection, execute a query, and close the connection in order to create custom keywords for database testing.

By 
Oliver Howard user avatar
Oliver Howard
·
Oct. 25, 17 · Tutorial
Likes (7)
Comment
Save
Tweet
Share
17.6K Views

Join the DZone community and get the full member experience.

Join For Free

Katalon Studio allows users to create custom keywords to address specific needs. With custom keywords, you can connect to databases and perform database testing. This tutorial describes details on how to create custom keywords for database testing in Katalon Studio.

Below is a code sample demonstrating how to:

  • Establish a database connection
  • Execute a query
  • Close the connection
package com.database
import java.sql.DriverManager
import java.sql.ResultSet
import java.sql.Statement
import com.kms.katalon.core.annotation.Keyword
import com.mysql.jdbc.Connection
public class DemoMySql {
 private static Connection connection = null;
 /**
 * Open and return a connection to database
 * @param dataFile absolute file path
 * @return an instance of java.sql.Connection
 */
 //Establishing a connection to the DataBase
 @Keyword
 def connectDB(String url, String dbname, String port, String username, String password) {
  //Load driver class for your specific database type
  String conn = "jdbc:mysql://" + url + ":" + port + "/" + dbname
  //Class.forName("org.sqlite.JDBC")
  //String connectionString = "jdbc:sqlite:" + dataFile
  if (connection != null && !connection.isClosed()) {
   connection.close()
  }
  connection = DriverManager.getConnection(conn, username, password)
  return connection
 }
 /**
 * execute a SQL query on database
 * @param queryString SQL query string
 * @return a reference to returned data collection, an instance of java.sql.ResultSet
 */
 //Executing the constructed Query and Saving results in resultset
 @Keyword
 def executeQuery(String queryString) {
  Statement stm = connection.createStatement()
  ResultSet rs = stm.executeQuery(queryString)
  return rs
 }
 //Closing the connection
 @Keyword
 def closeDatabaseConnection() {
  if (connection != null && !connection.isClosed()) {
   connection.close()
  }
  connection = null
 }
 /**
 * Execute non-query (usually INSERT/UPDATE/DELETE/COUNT/SUM...) on database
 * @param queryString a SQL statement
 * @return single value result of SQL statement
 */
 @Keyword
 def execute(String queryString) {
  Statement stm = connection.createStatement()
  boolean result = stm.execute(queryString)
  return result
 }
}

Tip: Press Ctrl + Shift + o to automatically import missing libraries in test scripts.

The custom keywords file will look like the following:

Katalon Custom Keywords

You can add the sample code above your keyword file and modify the details as appropriate. Refer to these links for the formats of database connection strings:

  • MSSQL
  • Oracle

Use Defined Keywords in Test Cases for DB Testing

1. Create new custom keywords for database connection (see above).

2. Copy the DB script provided above and paste it into the new keyword editor as illustrated below:Katalon Defined Keywords

For more tutorials about automation testing tools, please visit Katalon Studio's Tutorials.

Database connection Katalon Studio

Opinions expressed by DZone contributors are their own.

Related

  • Spring Microservice Tip: Abstracting the Database Hostname With Environment Variable
  • Top Automation Testing Tools for 2024
  • Spring Microservice Application Resilience: The Role of @Transactional in Preventing Connection Leaks
  • Building and Integrating REST APIs With AWS RDS Databases: A Node.js Example

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: