我正在开始使用 Eclipse IoT,在尝试创建 SQL 连接器时出现以下错误。我已经在Windows中添加了类路径,并且按照https://stackoverflow.com/questions/8745872/classnotfoundexception-com-mysql-jdbc-drive中的建议将相应的.jar库添加到项目中。我不明白为什么我仍然收到此错误。有什么想法吗?
生成错误的代码:
public static void getConnection(){
try{
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException e){
System.out.print(" Class.forName cannot be found");
e.printStackTrace();
}
我明白了:
Class.forName cannot be foundjava.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at controller.establishConnection.getConnection(establishConnection.java:17)
最佳答案
如果它是一个Web项目:检查jar(或包含jar的文件夹)是否确实位于项目的部署程序集(在项目属性中设置)中。如果没有,请添加它。
关于mysql - 为什么我在 Eclipse IoT 上不断收到 ClassNotFoundException : com. mysql.jdbc.Driver 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35865026/