New to IntelliJ: JDBC Connection Problems
已回答
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?
请先登录再写评论。
Make sure JDBC jar is added to the module dependencies: http://www.jetbrains.com/idea/webhelp/configuring-module-dependencies-and-libraries.html.
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.
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.
Serge have files zipped and ready to go. How do I get them to you?
https://intellij-support.jetbrains.com/hc/en-us/articles/206869619-Uploading-Large-Files-for-JetBrains-Support-Team
The project you have provided still uses "com.sql.jdbc.Driver" instead of "com.mysql.jdbc.Driver", hence the problem.
Thank you. I had a preconceived notion that it was in the tool settings not the code.