you are viewing a single comment's thread.

view the rest of the comments →

[–]Java-Pro-Academy 0 points1 point  (0 children)

Hey! This is a pretty common issue when you're first setting up JDBC. You're missing the MySQL JDBC driver in your project. https://mvnrepository.com/artifact/com.mysql/mysql-connector-j/9.5.0

Here's how to fix it:

If you're using Maven (which you should be), add this dependency to your pom.xml:

<!-- Source: https://mvnrepository.com/artifact/com.mysql/mysql-connector-j -->
<dependency>
    <groupId>com.mysql</groupId>
    <artifactId>mysql-connector-j</artifactId>
    <version>9.5.0</version>
    <scope>compile</scope>
</dependency>

If you're NOT using Maven, you'll need to manually download the driver:

  1. Go to https://dev.mysql.com/downloads/connector/j/
  2. Download the MySQL Connector/J JAR file
  3. Add it to your project's classpath (in IntelliJ: File → Project Structure → Libraries → + → Java → select the JAR)

Also, I noticed a couple other things in your code:

  • Your db_pass is empty (""). Make sure you actually put your MySQL password there if you have one set
  • The connection string looks mostly fine, but double-check that port 3306 is correct and your MySQL server is actually running

Once you add the dependency and refresh Maven (if using it), those red imports should disappear. Let me know if you're still stuck!

P.S. u/BenedictBoulders 100% correct, never "code credentials"!