New to IntelliJ: JDBC Connection Problems

Answered

New to IntelliJ,  Code from MySQL and Java Developers Guide by Matthews, et al;

public class test {

public static void main(String[] args) {
try {
forName("com.sql.jdbc.Driver").newInstance();
System.out.println("Good to Go!");
} catch (Exception E) {
System.out.println("JDBC Driver error");
}
}
}

Added MySQL driver as external library but IntelliJ wont see the MySQL library when I run the file.  Where do I configure this in IntelliJ?

7 comments
Comment actions Permalink

Hi

I have now added the jar to the module dependencies. Closed the IDE and reopened and see the jar in the external libraries node.  However still get the JDBC Driver Error when the class runs.

0
Comment actions Permalink

For MySQL driver the code would look like:

try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}

If it still doesn't work, please share a complete sample project to reproduce the problem.

1
Comment actions Permalink

Serge have files zipped and ready to go. How do I get them to you?

0
Comment actions Permalink

The project you have provided still uses "com.sql.jdbc.Driver" instead of "com.mysql.jdbc.Driver", hence the problem.

0
Comment actions Permalink

Thank you.  I had a preconceived notion that it was in the tool settings not the code.

0

Please sign in to leave a comment.