【发布时间】:2015-09-09 11:20:41
【问题描述】:
我正在尝试从 Access 数据库中获取详细信息并在我的 selenium 脚本中使用这些值,但不知何故我无法这样做。虽然我能够成功连接到数据库并在控制台中打印值。我无法在脚本中使用相同的值。这是我正在使用的代码。如果我出错了,请告诉我。
package AccessDB;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
public class Sample_Access_DB_Test {
public static WebDriver driver;
public static String dbLocation;
public static Connection con;
public static Statement smt;
public static ResultSet rs;
@Test
public void f() throws Exception {
//Database Location
dbLocation = "D:\\AccessDB's\\Userinfor1.accdb";
//Connecting to the Database
con = DriverManager.getConnection("jdbc:odbc:ADB");
System.out.println("Connection Establised Successfully");
//Creating DB statement
smt = con.createStatement();
System.out.println("Statement Successfully Created");
//Executing Created Statement
rs = smt.executeQuery("Select * from Userinfor1");
System.out.println("Query Executed");
while(rs.next()){
System.out.println(rs.getString(2));
//System.out.println(rs.getString(3));
//System.out.println(rs.getString(4));
}
driver.findElement(By.id("login-username")).sendKeys(rs.getString(2));
/*
driver.findElement(By.id("login-username")).sendKeys("gopi_krishna28");
driver.findElement(By.id("login-passwd")).sendKeys("gopikrishna28");
driver.findElement(By.id("login-signin")).click();*/
}
@BeforeTest
public void beforeTest() {
driver = new FirefoxDriver();
driver.get("http://www.yahoomail.com/");
}
@AfterTest
public void afterTest() {
}
}
这是抛出的错误
java.sql.SQLException: [Microsoft][ODBC Driver Manager] 游标状态无效
【问题讨论】:
标签: java ms-access selenium jdbc webdriver