Generally We don’t have to Test entire database of our application.To my knowledge, We use Selenium to test the Database whether data given in the front end(UI) is as same as the data present in the Database(Back End).
Note: We don’t do negative testing in database.
Here i am using MySql to test the database.
You need to Download Java.sql jar and configure database in your system. I’ll explain database configuration in Upcoming posts.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.Test;
public class testng_8
{
public WebDriver fd;
@Test
public void method_sql() throws Exception
{
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
Connection cn=DriverManager.getConnection(“jdbc:mysql:wombat”, “myLogin”, “myPassword”);
Statement st=cn.createStatement();
ResultSet rs= st.executeQuery(“select * from emp”);
try {
while (rs.next())
{
System.out.println(rs.getString(0));
}
cn.close();
}
catch (Exception e)
{
System.out.println(“invalid”);
}
}
}
Note: We don’t do negative testing in database.
Here i am using MySql to test the database.
You need to Download Java.sql jar and configure database in your system. I’ll explain database configuration in Upcoming posts.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.Test;
public class testng_8
{
public WebDriver fd;
@Test
public void method_sql() throws Exception
{
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
Connection cn=DriverManager.getConnection(“jdbc:mysql:wombat”, “myLogin”, “myPassword”);
Statement st=cn.createStatement();
ResultSet rs= st.executeQuery(“select * from emp”);
try {
while (rs.next())
{
System.out.println(rs.getString(0));
}
cn.close();
}
catch (Exception e)
{
System.out.println(“invalid”);
}
}
}