Here is my code:
import java.sql.*; import com.mysql.jdbc.Driver; public class Main { public void connect() { Connection con = null; try { Class.forName("com.mysql.jdbc.Driver"); con = DriverManager.getConnection("jdbc:mysql//localhost:3306/mydb", "dev", "pass"); } catch (Exception e) { e.printStackTrace(); } finally { if (con != null) try { con.close(); } catch(Exception e) {} } } public static void main(String[] args) { Main m = new Main(); m.connect(); } } I have imported mysql-connector-java-5.1.39.jar as a library in IntelliJ and as you can see the driver is imported in the code.
But I get:
java.sql.SQLException: No suitable driver found for jdbc:mysql//localhost:3306/mydb I have looked at countless stack overflow questions and I can't figure out what more it needs to at least attempt a connection. I have a local SQL server running, and I've double checked the port and database name.
Any ideas would be appreciated, thanks.
EDIT: this is not a duplicate. The solution to the other question that someone flagged is not relevant here. I had already added the jar as a library for the project, as described in the other question. Also, the crash doesn't happen on the "Class.forName" part, it crashes on the subsequent line.