Thursday, March 10, 2011

MYSQL

How do you start and stop MySQL on Windows?  - net start MySQL, net stop MySQL


What’s the default port for MySQL Server? - 3306


What does tee command do in MySQL? - tee followed by a filename turns on MySQL logging to a specified file. It can be stopped by command notee.


Use mysqldump to create a copy of the database? - mysqldump -h mysqlhost -u username -p mydatabasename > dbdump.sql

Tuesday, March 8, 2011

Connect mysql with selenium



How to connect DB with seleniumRC

First you should now which table want to use and columns names.

Here we are connecting mysql and getting the username and password from "users" table. In this table "userEmail" & "password" columns.

A program can also explicitly load JDBC drivers at any time. For example, the my.sql.Driver is loaded with the following statement:
 Class.forName("my.sql.Driver");

When the method getConnection is called, the DriverManager will attempt to locate a suitable driver from amongst those loaded at initialization
and those loaded explicitly using the same classloader as the current applet or application.

Connect with Mysql/Oracle along with authentication

Connection conn = DriverManager.getConnection(url,"username","password");
then execute quires and store the data in a result set

Now you can use the stored data.
Here is an example for "Login", user email and password getting from the user table with mysql drivers.


// Connect my sql DB and get the user emailid with selenium  
package com.sasidhar.wf;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import com.thoughtworks.selenium.*;
import java.sql.DriverManager;
import java.util.regex.Pattern;

public class Test extends SeleneseTestCase {
public void setUp() throws Exception {
setUp("http://your applicaiton url/", "*chrome");
}

public void testUntitled() throws Exception {
//this is mysql connection

Class.forName("com.mysql.jdbc.Driver") ;
String url = "jdbc:mysql://database host address/dbname";
Connection conn = DriverManager.getConnection(url,"username","password");
Statement stmt = conn.createStatement();
ResultSet result =  stmt.executeQuery("select useremail from user where userID=1");
while (result.next()) {
String emailaddress = result.getString("userEmail");

selenium.open("your applicaiton url/");
selenium.type("formField1", emailaddress);
selenium.type("formField2", "password");
selenium.click("Login");
selenium.waitForPageToLoad("30000");


}
}
}