In selenium testing how to connect with database , any one

pls give the entire information

Answer Posted / sandip

public class dbconnection
{
public static void main(String args[])
{
String email;
String dbUrl = "jdbc:mysql://localhost:3306/test"; //This
URL is based on your IP address
String username="username"; //Default username is root
String password="password"; //Default password is root
String dbClass = "com.mysql.jdbc.Driver";
String query = "Select email from users where user_id = 1;";

try
{

Class.forName(dbClass);
Connection con = DriverManager.getConnection
(dbUrl,username,password);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);

while (rs.next())
{
dbtime = rs.getString(1);
System.out.println(email);
} //end while

con.close();
} //end try

catch(ClassNotFoundException e)
{
e.printStackTrace();
}

catch(SQLException e)
{
e.printStackTrace();
}

} //end main

} //end class

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Do you know how to check if a button is enabled on the page?

537


Tell us how can you create html test report from your test script?

530


what is the difference between keyword driven frame work and data driven frame work.

1880


Can any one give me the script for drag and drop or setselection functions ?like in a not pad i want to select 5 lines

1436


Please explain what is a relative xpath?

570






Why do you want to keep this kind of information in a separate file and not directly in the code?

597


What are the advantages of test automation?

580


Tell me what are pros and cons of automating tests at ui layer?

527


List of Test Management Tools??Is Quality Center Test Management tools

1342


Explain me what is testng and why is it better than junit?

515


hi i would like to know is there any training institue for Calabash,robotium and ui automator in hyderabad...urgent

2581


Do you know what is the purpose of creating a reference variable- 'driver' of type webdriver instead of directly creating a firefoxdriver object or any other driver's reference in the statement webdriver driver = new firefoxdriver();?

519


How does load testing work for websites?

626


Give some examples for defect management tools?

568


How do you select which automation tool is best suited for you?

534