代码片段:
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 驱动程序...
.zip
.jar
到项目的类路径中。本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句