0

Ok, so I wanted to connect the MySQL connecter to intellij idea. I added the jar file to the module (also wrote requires mysql.connecter.java in the module.info file) and also added that jar file to the library. Here's the following code and under it, I wrote the issue I am having:

package sample;

import java.lang.Class;
import java.sql // And when I try to import java.sql, it shows me that I can't import it

public class DBConnection {

public static void main(String[] args) throws ClassNotFoundException {

    Class.forName("com.mysql.jdbc.Driver");
    // I can't import the Connection class and the DriverManager class
}
}

What am I doing wrong? Any help would be appreciated. Thank You!!

kleopatra
  • 51,061
  • 28
  • 99
  • 211
  • Does this answer your question? [Correct way to add external jars (lib/\*.jar) to an IntelliJ IDEA project](https://stackoverflow.com/questions/1051640/correct-way-to-add-external-jars-lib-jar-to-an-intellij-idea-project) – Arvind Kumar Avinash Apr 07 '20 at 01:39
  • Are you using a modular project? If so, you need to add `requires java.sql;` to `module-info.java`, or you need to remove `module-info.java` to make it non-modular. And to be clear, you can't have a statement `import java.sql`, you would need to be specify and explicit class, `import java.sql.Connection`, or use a wildcard, `import java.sql.*`. – Mark Rotteveel Apr 07 '20 at 15:45

0 Answers0