It provides methods for querying and updating data in a database. From a technical point of view, the API is as a set of classes in the package. To use JDBC with a particular database, we need a JDBC driver for that database. By default Resultset reference 'rs' points to before first row. When it returns true we retrieve the data in first row.

Here integer means column position and string means column name of the record. And last tear Down() has close connection which will close the database connection if it is opened.

xxx indicates primitive datatypes or string object. Output of the above program should look like below: Till now we have seen example on how to access database,now let us see how we actually perform database testing using Selenium.

For registering the Driver we Load the Driver class using for Name() method.

Retrieving records: for executing select queries(for fetching records) we call a method called execute Query(String qry) by taking string as parameter.

Now we need to get the records from Result Set object.

To access the resultset object it uses a method called next() which presents in Result Set Interface.

Other case can be like, after performing any action, we may want to check the data displayed in the UI is correct by comparing the Database. Do let us know if have come across any difficulties when working with the above program and feedback is also welcome.

You might also want to check Java tutorial, Postgre SQL Java tutorial, Apache Derby tutorial, My SQL tutorial, or Spring Jdbc Template tutorial on Zet Code.

where as JDBC API is a specification provides set of interfaces which are written and developed in Java programming language. The below are the Steps to Connect to database, before proceeding, you need to have My SQL Connector. This method contains three arguments of string type.

You can download from here Download My SQL Connector Jar and add it the build path as we add selenium webdriver jar. i.e., url, username and password For executing queries there are different methods present in Statement Interface for retrieving records and for updating records.

JDBC is a cornerstone for database programming in Java.