Java JDBC Driver Help - (java.sql.SQLException: No suitable driver found)

Answered

I'm having issues getting Intelli J setup with driver. I have a local MySQL database that I'm able to establish connection with.

I then went to File > Project Struture > Library > Add Maven. I added the Java mysql connector.

Here's my code:

```

import java.sql.*;

public class JDBCDemo {
public static void main(String[] args) {

// establish DB url
String url = "jdbc.mysql://localhost:8800/employees_database";

try {
// Establish a DB Connection Object
Connection conn = DriverManager.getConnection(url, "root", "rootroot");

// create a statement object to send to the db
Statement statement = conn.createStatement();

// execute statement object by running
// query and storing results in
// a resultSet
ResultSet resultSet = statement.executeQuery("SELECT * FROM employees_tbl");

// process the result with a loop
while (resultSet.next()){
System.out.println(resultSet.getString("name"));
}

} catch (SQLException e) {
e.printStackTrace();
}
}
}


```

Here's my error message

I'm using the latest version of IntelliJ:

IntelliJ IDEA 2018.3 (Ultimate Edition)
Build #IU-183.4284.148, built on November 21, 2018

1
3 comments

Hello Thas,

Have you got a MySQL JDBC driver jar file on your runtime path?

 

0
Avatar
Permanently deleted user

I do have a 'mysql-connector-java-8.0.13.jar' file which I thought the above process added it to the runtime path. How exactly do I add it to the runtime path?

0

Thas,

Please check that JAR is mentioned in "Project Structure | Modules - Dependencies". D0o you use any build system (Maven, Gradle)?

1

Please sign in to leave a comment.