Home » Uncategorised » Database Testing

Newly Updated Posts

Database Testing

package SeleniumArchitecture;

import java.sql.DriverManager;
import java.sql.ResultSet;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.Statement;

public class FirstTestScript {

public static void main(String[] args) throws InterruptedException, InstantiationException, IllegalAccessException, ClassNotFoundException {
/*
* System.setProperty(“webdriver.gecko.driver”,
* “C:\\Users\\Girvar Singh Negi\\Desktop\\Eclipse_Installer\\GeckoDriver\\geckodriver.exe”
* ); WebDriver driver = new FirefoxDriver();
* driver.get(“http://www.facebook.com”);
*
* Thread.sleep(5000); driver.quit();
*/
java.sql.Connection conn =null;
try {
String url=”jdbc:mysql://localhost:3306/”;
String driver=”com.mysql.jdbc.Driver”;
String dbName=”Girvar”;
String username =”root”;
String password=””;

Class.forName(driver).newInstance();

conn = DriverManager.getConnection(url+dbName, username, password);
System.out.println(conn.isClosed());
java.sql.Statement st=conn.createStatement();
ResultSet rs= st.executeQuery(“select * from EMPLOYEE”);

/////////////////////////////////prepare statement interface /////////////////////////////

PreparedStatement pst= (PreparedStatement) conn.prepareStatement(“select * from employee where name=? and age=?”);

/*
* pst.setString(arg0, arg1); pst.setInt(parameterIndex, x);
*/

while(rs.next()) {
System.out.println(rs.getString(1)+rs.getString(2));

}

} catch (Exception e) {
e.printStackTrace();
}finally {

}

}

}