简体   繁体   English

Eclipse Java项目forName()classNotFoundException

[英]Eclipse java project forName() classnotfoundexception

I am trying to do a Java Project in Eclipse in Win7 and I wanted to test some methods. 我试图在Win7中的Eclipse中执行Java项目,我想测试一些方法。 But when I run as Java application I get this error: 但是,当我run as Java application此错误:

java.lang.ClassNotFoundException

And it also pointed this line: 它也指出了这一行:

Class.forName("ceng.mysql.jdbc.Driver");

I looked at some questions here with the same error code and it is like there is a different syntax for this code. 我在这里用相同的错误代码查看了一些问题,就像该代码有不同的语法一样。 But my teacher gave me this code and it was working in Ubuntu. 但是我的老师给了我这段代码,它可以在Ubuntu中工作。 Maybe this is caused because I use Windows. 也许是由于我使用Windows引起的。

I have 2 files in the same package, one of them is the Main.java. 我在同一包中有2个文件,其中一个是Main.java。 I put the mysql...jar thing on a folder named lib inside the project and put it also to the build path. 我将mysql ... jar放在项目内部名为lib的文件夹中,并将其也放置到构建路径中。

Anyway, how can I fix this? 无论如何,我该如何解决? Thank you for advance :) 谢谢你的进阶:)

change 更改

Class.forName("ceng.mysql.jdbc.Driver");

to

Class.forName("com.mysql.jdbc.Driver");

There is a package called com.mysql.jdbc in the jar you have added and inside that a class named Driver is there. 在您添加的jar中有一个名为com.mysql.jdbc的程序包,其中有一个名为Driver的类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM