Saturday 19 November 2016

Database Testing with Appium & JDBC



Appium is limited to testing your mobile applications. To use Appium for Database Testing you need to use the JDBC ("Java Database Connectivity").JDBC (Java Database Connectivity) is a SQL level API which allows you to execute SQL queries using java code . JDBC is used for enabling  connectivity between the Java Programming language and a wide range of databases. 

To test with database we need to learn how to connect with database first then how to execute queries followed by how to process the results.

Video Tutorial -



1. Connect to Database -

In order to make a connection to the database the syntax is as per given below and after connection setup you also need to load the JDBC Driver.


Connection con = DriverManager.getConnection(dbUrl,username,password);

Class.forName("com.mysql.jdbc.Driver"); 

Where,
  • Userid is the username configured in the database
  • Password of the configured user
  • URL is of format jdbc:< dbtype>://ipaddress:portnumber/db_name"

2.  Execute Queries -

Once connection is made, you need to execute queries.You can use the Statement Object to send queries. First Create Statement and once the statement object is created use the executeQuery method to execute the SQL queries.

Statement stmt = con.createStatement();

ResultSet rs=stmt.executeQuery(select * from employee); 

 

3. Process Results -

As in above example we have seen that after query execution the result is stored in  ResultSet Object. with this class object we can perform loads of actions to process an test the results as per our requirement.
  • String getString() - get the string type data from ResultSet.
  • int getInt() - get the integer type data from ResultSet.
  • double getDouble() - get the double type data from ResultSet.
  • Date getDate() - get the date type data from ResultSet.
  • boolean next() - move to next record in the ResultSet.
  • boolean previous() - move to previous record in the ResultSet.
  • boolean first() - move to first record in the ResultSet.
  • boolean last() - move to last record in the ResultSet.
  • boolean absolute(int rowNumber) - move to perticular record in the ResultSet.
 

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This is an awesome post.Really very informative and creative contents.
    Wordpress Development company in Chennai

    ReplyDelete
  3. I read this article, it is really informative one. Your way of writing and making things clear is very impressive. Thanking you for such an informative article.minecraft coding course

    ReplyDelete