java.lang.ClassNotFoundException:com.mysql.jdbc.Driver。 [英] java.lang.ClassNotFoundException: com.mysql.jdbc.Driver.

查看:187
本文介绍了java.lang.ClassNotFoundException:com.mysql.jdbc.Driver。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



错误消息:




无法连接到databasejava.lang.ClassNotFoundException:com.mysql.jdbc.Driver




代码:



 <%
try {
Class.forName(com.mysql.jdbc。驱动程序)的newInstance();
连接myCon = DriverManager.getConnection(jdbc:mysql:// localhost / myDB,root,password);
if(!myCon.isClosed())
out.println(成功连接到+MySQL服务器!);

myCon.close();
} catch(Exception ex){
out.println(Unable to connect to database+ ex);
}
%>

我知道这个问题已经被问到这里,但是我仍然无法排除这个东西。



环境变量:




JAVA_HOME:C:\Program Files\Java\jdk1.7.0_51



CLASSPATH:。%JAVA_HOME%\lib; C:\Program Files\MySQL\Connector J 5.1.29;


我如何解决这个问题?

解决方案

Eclipse项目不知道你在哪里数据库。您需要将它们包含在WEB-INF / lib目录下,以便它们成为类路径的一部分。


I am using Java/Eclipse to connect to MySQL database but encountering the following error.

Error Message:

Unable to connect to databasejava.lang.ClassNotFoundException: com.mysql.jdbc.Driver

Code:

<%
  try {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection myCon = DriverManager.getConnection("jdbc:mysql://localhost/myDB", "root", "password");
    if(! myCon.isClosed())
      out.println("Successfully connected to " + "MySQL server!");

    myCon.close();
  }catch(Exception ex){
      out.println("Unable to connect to database" + ex);
  }      
%>

I know that this question has already been asked here but still I am unable to sort this thing out.

Environmental variables:

JAVA_HOME: C:\Program Files\Java\jdk1.7.0_51

CLASSPATH: .%JAVA_HOME%\lib;C:\Program Files\MySQL\Connector J 5.1.29;

How can I can solve this issue?

解决方案

The Eclipse project doesn't know where you have the drivers for the database. You need to include them under the WEB-INF/lib directory so that they become part of the classpath.

这篇关于java.lang.ClassNotFoundException:com.mysql.jdbc.Driver。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆