Error loading driver:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
2011-09-08 11:12
816 查看
错误:Error loading driver:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
相关代码如下:
public static Connection getConnection() {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/test2?useUnicode=true", "root","root");
return (connection);
} catch (ClassNotFoundException cnfe) {
System.err.println("Error loading driver:" + cnfe);
return null;
} catch (SQLException sqle) {
System.err.println("Error connection:" + sqle);
return null;
}
}
改正方法:
1)ClassPath中缺少你想要的mysql的JDBC包,操作如下:
将mysql-connector-java-5.1.6-bin(具体版本看自己的mysql版本)导入工程中,eclipse 中只要右击工程文件夹属性选项-Java Build Path-Libraries-Add Extenal JARs 添加即可……
2)将该包放入 \WEB-INF\lib 下面
相关代码如下:
public static Connection getConnection() {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/test2?useUnicode=true", "root","root");
return (connection);
} catch (ClassNotFoundException cnfe) {
System.err.println("Error loading driver:" + cnfe);
return null;
} catch (SQLException sqle) {
System.err.println("Error connection:" + sqle);
return null;
}
}
改正方法:
1)ClassPath中缺少你想要的mysql的JDBC包,操作如下:
将mysql-connector-java-5.1.6-bin(具体版本看自己的mysql版本)导入工程中,eclipse 中只要右击工程文件夹属性选项-Java Build Path-Libraries-Add Extenal JARs 添加即可……
2)将该包放入 \WEB-INF\lib 下面
相关文章推荐
- Class.forName("com.mysql.jdbc.Driver");报错java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
- IDEA下使用JDBC连接数据库遇到java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
- 使用tomcat产生java.lang.ClassNotFoundException: com.mysql.jdbc.Driver问题
- java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
- java.lang.ClassNotFoundException: com.mysql.jdbc.Driver (in EnvironmentClassLoader[resin-system:,NEW
- java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 解决方法
- java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 解决方法
- How to install MySQL JDBC driver in Eclipse web project without java.lang.ClassNotFoundexception com
- Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
- 【食堂管理项目记录】java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
- 连接mysql的时候出现:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
- JUnit测试通过,但控制台Console中有报错:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
- 解决:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
- java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
- java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
- java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
- java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
- java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 解决方法
- java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
- IDEA连接mysql教程,以及出现java.lang.ClassNotFoundException: com.mysql.jdbc.Driver的解决办法