java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/DB3

第一:

查看具体配置的路径是否错误,以及当前的DB3数据库是否存在。

如果地址填写错误(包括localhost或者端口3306写出都会)会报:

Exception in thread “main” com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)

即:链接错误,表达达不到一个正确的链接。
 

如果数据库不存在会报:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database ‘db3’

未知的数据库,也即不存在或者找不到。

第二:

初学者遇到这个问题:查看下mysql-connetctor-java-xxx.jar这个文件有没有加载进运行的环境。

选中这个jar文件,然后右键:add as library(添加为库)

.jar的方法里面封装了很多方法, No suitable driver 即:没有合适的驱动。由于没有将jar文件导入,所以方法找不到无法调用。

为什么这个问题偶尔会出现,因为早在很多年前,jar就会自动导入了,但是你在导入项目的时候出了bug,导致程序没有正常的执行,自动导入失败,所以需要手动导入一下。

参考阅读:https://blog.csdn.net/weixin_55599565/article/details/124517944

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
心中带点小风骚的头像心中带点小风骚普通用户
上一篇 2023年12月13日
下一篇 2023年12月13日

相关推荐