我需要使用SeleniumWebDriver(JAVA)连接到Oracle SQL开发人员。怎么做?

我需要使用SeleniumWebDriver(JAVA)连接到Oracle SQL开发人员。怎么做?,oracle,selenium,testing,selenium-webdriver,oracle-sqldeveloper,Oracle,Selenium,Testing,Selenium Webdriver,Oracle Sqldeveloper,我在网上查找了一些资源,他们使用的是一些“dbURL”,我在Oracle SQL Developer中找不到。有人能提供一些适当和明确的解决方案吗 如果您使用oracle,要了解您的URL是什么,您可以执行以下操作。有一个tnsnames.ora文件定义数据库地址。 此文件通常位于$ORACLE_HOME/network/admin中,供ORACLE客户端使用。以下是tns条目示例: ORA11 = (DESCRIPTION = (ADDRESS_LIST = (ADDR

我在网上查找了一些资源,他们使用的是一些“dbURL”,我在Oracle SQL Developer中找不到。有人能提供一些适当和明确的解决方案吗

如果您使用oracle,要了解您的URL是什么,您可以执行以下操作。有一个tnsnames.ora文件定义数据库地址。 此文件通常位于$ORACLE_HOME/network/admin中,供ORACLE客户端使用。以下是tns条目示例:

ORA11 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = hostname)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = ORA11)
    )
  )
通过此条目,您可以确定您的jdbc连接字符串为:

jdbc:oracle:thin:@hostname:1521:ORA11

如果您想通过java bellow连接到db,则是一个示例。首先,您必须拥有某种数据库服务器,在Oracle中,您将连接到该服务器。如果你遇到麻烦是因为司机

我使用maven,这是一种依赖性,您可能需要:

<!-- https://mvnrepository.com/artifact/com.oracle/ojdbc14 -->
<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc14</artifactId>
    <version>10.2.0.4.0</version>
</dependency>
希望这有帮助,

是一个桌面开发工具(类似于Eclipse或IntelliJ for Java)。这不是你能连接到的东西。您的意思是希望Selenium连接到Oracle数据库吗?
public class ConnectToDatabse {

Connection conn = null;
Statement stmt = null;
ResultSet resultSet = null;
WebDriver driver;

@BeforeTest
public void SetUpConnection() throws SQLException, ClassNotFoundException {

    // Register JDBC driver (JDBC driver name and Database URL)
    Class.forName("oracle.jdbc.driver.OracleDriver");

    // Open a connection
    conn = DriverManager.getConnection("jdbc:oracle:thin:@//HOSTNAME:PORT/SERVICENAME","user", "password");

    System.setProperty("webdriver.chrome.driver", "<Path of Driver>\\chromedriver.exe");
    ChromeOptions options = new ChromeOptions();

    // Code to disable the popup of saved password
    Map<String, Object> prefs = new HashMap<String, Object>();
    prefs.put("credentials_enable_service", false);
    prefs.put("password_manager_enabled", false);
    options.setExperimentalOption("prefs", prefs);
    driver = new ChromeDriver(options);
    driver.get("<URL>");
}
@Test
public void testTable() {
    try {
        // Execute a query
        stmt = conn.createStatement();
        resultSet = stmt.executeQuery("select * from sampletable");

        // Get the all row of UI Table
        List<WebElement> lstTr = driver.findElement(By.id("grdData")).findElements(By.tagName("tr"));

        // Index for Row
        int rowCount = 0;

        // Count of Matched Column
        int matchColumnCount = 0;

        // Count of Matched Row
        int matchRowCount = 0;

        System.out.println("Row Count => " + lstTr.size());

        // Extract the data from Table
        while (resultSet.next()) {


        List<WebElement> lstTd = lstTr.get(rowCount + 1).findElements(By.tagName("td"));
        System.out.println("Cloumn Count => " + lstTd.size());

        for (int j = 0; j < lstTd.size(); j++) {
            String uiCell = lstTd.get(j).getText();
            System.out.println("UI Cell Data => " + uiCell);

            /*
            * (j + 1) in the resultSet => because index is start from 1
            * and here loop is starting from 0
            */
            String dbCell = resultSet.getString(j + 1);
            System.out.println("DB Cell Data => " + dbCell);

            // Comparison between both string
            if (uiCell.trim().equalsIgnoreCase(dbCell.trim())) {
                matchColumnCount++;
            }
        }

        if (matchColumnCount == lstTd.size()) {
            matchRowCount++;
            System.out.println("========ROW MATCHED==========");
        }

        }
            assertEquals(matchRowCount, rowCount, "UI Table is the exact copy of Database Table");
    } catch (Exception e) {
            System.out.println(e);
    }
}
@AfterTest
public void CloseTheConnection() throws SQLException {

// Code to close each and all Object related to Database connection
if (resultSet != null) {
    try {
        resultSet.close();
    } catch (Exception e) {
    }
}

if (stmt != null) {
    try {
        stmt.close();
    } catch (Exception e) {
    }
}

if (conn != null) {
    try {
        conn.close();
    } catch (Exception e) {
    }
}

driver.quit();
}

}