As the industry moves into big data, databases play a significant role in maintaining information and holding the series. Database Validation and verification play an important role to ensure that there are no bugs while capturing the data and storing them.
There are two ways to achieve it either manually or through Automation.
During manual checking, one has to go through each entry that is getting maintained in the database when any transaction happens at the front end. However, since there are several movements on the computer, it gets more difficult, so it takes time to test all the tables one by one. So Selenium is one such method in Automation Software that aims to include functionalities for checking the database which is time-saving and cost-effective.
Selenium WebDriver is limited to using a Browser to check the applications. You need to use the JDBC (Java Database Connectivity) to use Selenium WebDriver for database verification.
JDBC (Java Database Connectivity) is a Database level API for running SQL statements. The communication between Java programming language and a broad variety of databases is responsible for this. The JDBC API contains the classes and interfaces below
Steps to establish Database connection
1) Make a connection to the Database
To make a connection with the database, the syntax will be
DriverManager.getConnection(URL, "userid", "password" )
Here,
And the end code will look like
Connection con = DriverManager.getConnection(dburl, username, password)
You also need to load the JDBC Driver using the below code
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver")2) Send Queries to the Database Once connection is made, you need to execute queries.
You can use the Statement Object to send queries.
Statement stmt = con.createStatement();
Once the statement object is created use the executeQuery method to execute the SQL queries
ResultSet rs = stmt.executeQuery(select * from employee;);
3) Process the results
Display the results using below code
while (rs.next()) {
String myName = rs.getString(0);
String myAge = rs.getString(1);
System.out.println(myName + " :::: " + myAge);
}
con.close();
Talk to us about how we bring together 1:1 personalisation, deep Martech Expertise, CX & Demand Gen Strategy, Engagement Analytics & Cross-Channel Orchestration to drive award winning experiences that convert
Get in touch for a complimentary consultation or a demo today.
Free workshops, expert advice & demos- to help your realize value with Sitecore
RegisterParticipate in our event survey , meet us at our booth , get free giveaways & a chance to win an iPhone 11
Let’s go