码迷,mamicode.com
首页 > 数据库 > 详细

SQLException: No suitable driver found for jdbc:mysql://localhost:3306/xxxx

时间:2016-09-22 18:20:45      阅读:266      评论:0      收藏:0      [点我收藏+]

标签:jdbc 08001 no suitable driver found

刚刚学习jsp,对着视频敲代码,报这个错误。

SQLException: No suitable driver found for jdbc:mysql://localhost:3306/shop

SQLState: 08001

VendorError: 0

问题,因为没有引入Driver类。

final String DBDRIVER = "org.gjt.mm.mysql.Driver";
String username = "root";
String password = "root";
String url = "jdbc:mysql://localhost:3306/shop";
Connection con = null;
try {
    Class.forName(DBDRIVER);
    con = DriverManager.getConnection(url, username, password);
} catch (SQLException e) {
    System.out.println("SQLException: " + e.getMessage());
    System.out.println("SQLState: " + e.getSQLState());
    System.out.println("VendorError: " + e.getErrorCode());
} catch (ClassNotFoundException e) {
    System.out.println("Class:" + e.getMessage());
}

加上Class.forName("xxxx")就OK了

本文出自 “PHP学习” 博客,请务必保留此出处http://xtceetg.blog.51cto.com/5086648/1855379

SQLException: No suitable driver found for jdbc:mysql://localhost:3306/xxxx

标签:jdbc 08001 no suitable driver found

原文地址:http://xtceetg.blog.51cto.com/5086648/1855379

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!