gpt4 book ai didi

java - 如何解决java.sql.SQLException : in integration of database with JDBC API?

转载 作者:行者123 更新时间:2023-11-29 10:04:33 26 4
gpt4 key购买 nike

代码片段:

package dbIntegrationwithJDBC;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Example1 {
public static void main(String[] args) throws SQLException, InterruptedException {
String host = "localhost";
String port = "3306";

Connection con = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/mastro1729", "root",
"mysql123");
Statement s = con.createStatement();
ResultSet rs = s.executeQuery("select*from credentials where Scenario='mastro1729'");
System.out.println(rs.getString("Username"));
System.out.println(rs.getString("Password"));

while (rs.next()) {

WebDriver driver = new ChromeDriver();
driver.get("https://login.salesforce.com");

driver.findElement(By.name("usernameOrEmail")).sendKeys(rs.getString("Username"));
driver.findElement(By.xpath("//button[text()='Continue']")).click();
Thread.sleep(3000);

driver.findElement(By.name("password")).sendKeys(rs.getString("Password"));
driver.findElement(By.xpath("//button[text()='Log In']")).click();
Thread.sleep(3000);

}
}
}

错误消息:

Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/mastro1729
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at dbIntegrationwithJDBC.Example1.main(Example1.java:23)

我正在尝试使用 JDBC API 连接到 MySQL 数据库。我在本地主机上使用 mastro1729 创建了 MySQL 数据库。我的代码似乎是正确的,我已将 mysql-connector-java.jar 文件添加到 eclipse 中。当我尝试将我的数据库与 JDBC API 集成时,我得到 java.sql.SQLException at DriverManager.getConnection();陈述。我已经尽力了,但还是无法解决问题。

我做错了什么?

最佳答案

项目类路径中似乎没有找到合适的 JDBC 驱动程序...

  • 独立下载平台 MySQL JDBC Driver从这里开始。
  • 解压下载的.zip
  • 将可执行文件 .jar 添加到项目的类路径中。

关于java - 如何解决java.sql.SQLException : in integration of database with JDBC API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52166650/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com