Selenium MySQL Database connectivity 

Here is the code for the connection to a mysql Database using Microsoft SQL Server JDBC driver.

public void DBtest() throws Exception
{
// Load Microsoft SQL Server JDBC driver.
Class.forName(“com.mysql.jdbc.Driver”);
// Prepare connection url.
String url = “jdbc:mysql://localhost/TEST_DB”;
// Get connection to DB.
Connection con = DriverManager.getConnection(url, “root”, “admin”);
// Create statement object which would be used in writing DDL and DML
// SQL statement.
Statement stmt = con.createStatement();
// Send SQL SELECT statements to the database via the
Statement.executeQuery
// method which returns the requested information as rows of data in a
// ResultSet object.
ResultSet result = stmt.executeQuery(“select email from user”);
if (result.next()){
// Fetch value of “email_address” from “result” object.
String emailaddress = result.getString(“email”);
// Use the fetched value to login to application.
selenium.open(“/”);
selenium.windowMaximize();
selenium.type(“login_email”, emailaddress);
}
}


Author: Pavandeep Puddupakkam on November 13, 2010
Category: Database Testing
Google Webdriver Forum -The Online Community for Google Webdriver and Selenium RC Users and Professionals

Leave a Reply

Last articles