Code snippet:
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);
}
}
}
Error message:
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)
I'm trying to connect to a MySQL database with JDBC API. I created the MySQL database with mastro1729 on localhost. My code seems correct and I have added mysql-connector-java.jar file to eclipse. While I am trying to integrate my database with JDBC API I am getting java.sql.SQLException at DriverManager.getConnection();
statement. I have tried my best and but I could not be able to resolve the problem.
What am I doing wrong?