[英]Struggling with - Class not found exception: com.mysql.jdbc.Driver in JAVA
In Netbeans ide 7.0, I am facing this particular problem.在 Netbeans ide 7.0 中,我面临着这个特殊问题。 I wrote the following line of code in my program我在我的程序中编写了以下代码行
Class.forName("com.mysql.jdbc.Driver").newInstance(); Class.forName("com.mysql.jdbc.Driver").newInstance();
This particular line is throwing an exception.此特定行引发异常。 And when I connected the same mysql db server from the "Services -> Databases -> Drivers -> MySQL(Connector/Jdriver)" in the netbeans 7.0, it got connected.当我从 netbeans 7.0 中的“服务 -> 数据库 -> 驱动程序 -> MySQL(连接器/Jdriver)”连接相同的 mysql 数据库服务器时,它已连接。 When I went into the properties of that connection I found that it is connecting the mysql server using the same class which I used in the line of code.当我进入该连接的属性时,我发现它正在使用我在代码行中使用的相同 class 连接 mysql 服务器。
I also read some of the forums such as我还阅读了一些论坛,例如
http://www.javakb.com/Uwe/Forum.aspx/java-setup/11895/ClassNotFoundException-com-mysql-jdbc-Driver-from-netbeans http://www.javakb.com/Uwe/Forum.aspx/java-setup/11895/ClassNotFoundException-com-mysql-jdbc-Driver-from-netbeans
but this 1 is for netbeans on Ubuntu.但这个 1 适用于 Ubuntu 上的 netbeans。 What about Windows? Windows呢?
also, went through all of the responses in here另外,浏览了这里的所有回复
http://forums.mysql.com/read.php?60,42473,42473#msg-42473 http://forums.mysql.com/read.php?60,42473,42473#msg-42473
I don't know what is wrong?我不知道出了什么问题? Please help.请帮忙。
Solution: Well the problem here was different.解决方案:这里的问题是不同的。 My netbeans was able to connect MySQL server through its own predefined services.我的 netbeans 能够通过自己的预定义服务连接 MySQL 服务器。 That was because the path of that class was defined in the driver it was using.那是因为 class 的路径是在它使用的驱动程序中定义的。 But in the project I was building, the class-path for MySQL driver was not set.但是在我正在构建的项目中,没有设置 MySQL 驱动程序的类路径。 So I just added the same driver "MySQL JDBC Driver" to my Project.所以我只是在我的项目中添加了相同的驱动程序“MySQL JDBC 驱动程序”。
It can be done, just go to the Project navigator which is on the left side.可以做到,只需 go 到左侧的项目导航器。 There you'll find the Libraries attached to your Project at the bottom of Project navigator.在那里,您会在项目导航器的底部找到附加到您的项目的库。 Then right click on the library, select "Add Library..." and then select the particular library from the Global Libraries present.然后右键单击库 select "Add Library..." 然后 select 来自全局库中的特定库。 In my case the connector class was present in the netbeans but the library was not added to my project.在我的情况下,连接器 class 存在于 netbeans 中,但该库未添加到我的项目中。
Thank you btw for your precious time.谢谢你的宝贵时间。
You need to download the connector from here: http://www.mysql.com/products/connector/ and include it in your classpath您需要从此处下载连接器: http://www.mysql.com/products/connector/并将其包含在您的类路径中
yes是的
Read more: http://javarevisited.blogspot.com/2012/03/jdbc-javalangclassnotfoundexception.html#ixzz2Ply4zLFF阅读更多: http://javarevisited.blogspot.com/2012/03/jdbc-javalangclassnotfoundexception.html#ixzz2Ply4zLFF
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.