java.lang.ClassNotFoundException:com.mysql.jdbc.Driver。 [英] 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屋!