0% found this document useful (0 votes)
6 views9 pages

STMWeek 6

The document outlines the requirements and steps for performing various database checkpoints using Java and MySQL, including default checks, custom checks, and runtime record checks. It details hardware and software prerequisites, JDBC connection steps, and provides example Java programs for each type of database check. Additionally, it includes instructions for setting up the database and creating necessary tables and records.

Uploaded by

akjjddjxjd39
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views9 pages

STMWeek 6

The document outlines the requirements and steps for performing various database checkpoints using Java and MySQL, including default checks, custom checks, and runtime record checks. It details hardware and software prerequisites, JDBC connection steps, and provides example Java programs for each type of database check. Additionally, it includes instructions for setting up the database and creating necessary tables and records.

Uploaded by

akjjddjxjd39
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

6.

Database checkpoint for Default check


Aim: to check default database checkpoint

Hardware Requirements
 Processor: Intel Core i3+
 RAM: 4 GB (8 GB recommended)
 Hard Disk: 10 GB free space
 System Type: 64-bit architecture preferred
 Internet Connection: Required

Software Requirements
Operating System: Windows 10 / 11

JDK-8+, Eclipse IDE, MySQL Server, MySQL Workbench (Optional


but Recommended), MySQL Connector (JDBC Driver)

Theory: Default Check is a type of database checkpoint where the stored database
value is directly compared with the expected predefined value using simple equality
validation.

JDBC (Java Database Connectivity) is an API provided by Java to connect and


interact with databases using SQL.

MySQL is an open-source Relational Database Management System (RDBMS) used


to store and manage structured data.

MySQL Connector is the official JDBC driver for MySQL [Link] is JAR file.

JDBC Connection Steps

Step 1: Load Driver (optional in modern Java)


[Link]("[Link]");

Step 2: Establish Connection


Connection con = [Link](url, user, password);

Step 3: Create Statement


Statement stmt = [Link]();

Step 4: Execute Query


ResultSet rs = [Link]("SELECT * FROM users");

Step 5: Close Connection


[Link]();

Important JDBC Classes

 DriverManager
 Connection
 Statement
 PreparedStatement
 ResultSet

Environment Setup Steps to Run Selenium Scripts


Step 1️Install Java
Step 2 Install MySQL Server
Step 3 Install MySQL Workbench (Optional but Recommended)
Step 4 Download MySQL Connector (JDBC Driver)

Step 5 Database Setup

Step 6 Create Java Project

Add JDBC JAR to Project:

 Eclipse →Project-Right Click Project- Build Path →configure Build path-


Library- Add External JAR

Step 7 Create Java Class

Step 8 Run Program

Program:
import [Link];
import [Link];
import [Link];
import [Link];

public class DefaultDBCheck {

public static void main(String[] args) throws Exception {

// Database credentials
String url = "jdbc:mysql://localhost:3306/stm_lab";
String username = "root";
String password = "root";

// Establish connection
Connection con = [Link](url, username, password);
Statement stmt = [Link]();

// INSERT DATA (Simulating UI Action)


String insertQuery =
"INSERT INTO employees (name, salary, status) VALUES " +
"('myh', '50000000', 'ACTIVE')";

int rowsInserted = [Link](insertQuery);

if (rowsInserted > 0) {
[Link]("Data Inserted Successfully");
}

// VERIFY INSERTED DATA


String selectQuery =
"SELECT * FROM employees;

ResultSet rs = [Link](selectQuery);

if ([Link]()) {

String namel = [Link]("name");


String status = [Link]("status");
if ([Link]("myh") && [Link]("ACTIVE")) {
[Link]("SIMULATED END-TO-END DB CHECK PASSED");
} else {
[Link]("DB CHECK FAILED - DATA MISMATCH");
}

} else {
[Link]("DB CHECK FAILED - RECORD NOT FOUND");
}

// Close resources
[Link]();
[Link]();
[Link]();
}
}

6 b) Database checkpoint for customcheck


A Custom Database Check verifies database values using user-defined conditions or logical rules instead
of simple equality comparison.

import [Link];
import [Link];
import [Link];
import [Link];

public class DatabaseCustomCheck {

public static void main(String[] args) throws Exception {

String url = "jdbc:mysql://localhost:3306/stm_lab";


String username = "root";
String password = "root";
Connection con = [Link](url, username, password);
Statement stmt = [Link]();

String query = "SELECT * FROM employees WHERE name='Ravi'";


ResultSet rs = [Link](query);

if ([Link]()) {

int salary = [Link]("salary");


String status = [Link]("status");

// 🔹 Custom Validation Logic


if (salary > 20000 && [Link]("ACTIVE")) {
[Link]("CUSTOM DATABASE CHECK PASSED");
} else {
[Link]("CUSTOM DATABASE CHECK FAILED");
}

} else {
[Link]("RECORD NOT FOUND");
}

[Link]();
[Link]();
[Link]();
}
}
6 c) Database checkpoint for runtime record check
Runtime Record Check verifies database records that are generated dynamically during program
execution using runtime input values.

Program:

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class DatabaseRuntimeRecordCheck {

public static void main(String[] args) throws Exception {

String url = "jdbc:mysql://localhost:3306/stm_lab";


String user = "root";
String password = "root";

Connection con = [Link](url, user, password);

// Generate Runtime Data


Random rand = new Random();
int randomNum = [Link](10000);
String runtimeUsername = "User" + randomNum;

String email = runtimeUsername + "@[Link]";


String status = "ACTIVE";
// Insert Runtime Record
String insertQuery =
"INSERT INTO users(username, email, status) VALUES (?, ?, ?)";

PreparedStatement insertStmt = [Link](insertQuery);


[Link](1, runtimeUsername);
[Link](2, email);
[Link](3, status);

[Link]();

// Verify Runtime Record


String selectQuery =
"SELECT * FROM users WHERE username=?";

PreparedStatement selectStmt = [Link](selectQuery);


[Link](1, runtimeUsername);

ResultSet rs = [Link]();

if ([Link]()) {

String dbEmail = [Link]("email");


String dbStatus = [Link]("status");

if ([Link](email) && [Link](status)) {


[Link]("RUNTIME RECORD CHECK PASSED");
} else {
[Link]("RUNTIME RECORD CHECK FAILED");
}

} else {
[Link]("RECORD NOT FOUND");
}

[Link]();
[Link]();
[Link]();
[Link]();
}
}

DATABASE SETUP

CREATE DATABASE stm_lab;

USE stm_lab;

CREATE TABLE employees (


id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50),
salary INT,
status VARCHAR(20),

);
INSERT INTO employees(name, salary, status)
VALUES ('Ravi', 25000, 'ACTIVE');

You might also like