总结解决 No suitable driver found for jdbc:mysql//localhost:3306/ 问题的解决方案,各种情况都已囊括,希望可以帮助到有需要的各位

懂得都懂,看着这几行报错看了好几天,差点吐血!

 查遍全网,无一例外,都是总结为以下三个问题:

1.URL格式问题,数据库名后面加一串声明之类的

(事后证明url有无声明跟连接数据库毫无关系)

2.驱动字符串

(其实只要是比较高版本的jdk,都会像下图一样报错并提示驱动字符串要加cj.而不是报No suitable driver,所以并不是这个问题)

 

driver=com.mysql.cj.jdbc.Driver
driver=com.mysql.jdbc.Driver


3.Classpath中没有加入合适的mysql_jdbc驱动

(意思就是假如数据库版本5.0.x要对应驱动包版本5.0.x,假如数据库8.0.x要对应驱动包8.0.x,这是笔者在最后把问题解决的前提,所以读者一定要先把版本先对应好)

可是检查了上述问题的地方过百遍,没有任何问题,都快要砸电脑了!!!!!!

但是最后,终于,终于,终于找到问题所在!!

原来笔者电脑上居然安装了两个MySQL,一个是5.1版本,一个是8.0.29最新版,而且两个数据库的端口都设置成了3306(而且之前在安装MySQL时,环境变量居然也没有配置好),这就导致我对自己电脑数据库的认知出现错误(以为我的电脑只有一个8.0.29版本的MySQL),因为我使用的SQLyog默认连接的就是MySQL8.0.29版本的MySQL,我之前用命令行进入MySQL时,我一直以为我在使用8.0.29版本的MySQL(事后才知道用命令行默认进入的是MySQL5.1,怪不得之前把进程里的一个MySQL进程关闭后再进入命令行中的MySQL后,显示的表才能与SQLyog对应上,因为这操作是从本站某篇文章<命令行里的数据库和SQLyog数据库对应不上>看到的处理方法,文中说道:只要把进程里的MySQL进程关掉后在命令行上重新通过cd进入MySQL路径打开MySQL就能对应上SQLyog的数据),

所以最后总结:导致报错的原因可能有两个,

一是MySQL环境变量没有配置好,导致eclipse压根没办法找到8.0.29版本MySQL的打开路径(这是大概率问题所在,所以读者假如在文章开头写的三个问题都尝试过还是报错No suitable driver的话,就可以检查一下自己的MySQL的环境变量配置有没有出现问题),

二是电脑上装有不止一个MySQL,而且端口都是一样的,有可能就导致了无法正常连接数据库了(检查电脑上是不是装了多个数据库,发现是的话,可以检查环境变量写的路径是不是自己一直在使用的数据库的路径,同时把其它不用的数据库都卸载干净).

此外,笔者由于是初学者,所以在最终解决问题之前还尝试了很多思路去解决问题,以下列出以供各位读者参考,各路高手勿喷.

是不是jdk版本问题或者是不是eclipse版本问题

因为笔者看到有文章提到报错No suitable driver的同时驱动是加载成功的,所以是因为8.0.x版本的MySQL既要与8.0.x版本的驱动jar包对应还要与13.0版本的jdk对应,所以笔者就去尝试把jdk更新成13.0版本,但是发现eclipse版本巨旧(在java1234课程里下载的版本)导致无法使用13.0版本的jdk,所以就又去把eclipse更新成最新版本,然后把jdk更新成13.0,发现还是不行,所以与eclipse版本无关,也与jdk版本无关,因为最后找到原因所在后尝试使用哪个版本的jdk都可以连接成功的.

是不是MySQL版本和驱动jar包版本问题

其实是有关系的,但是文章开头陈述的三个问题解决方案中已经写到,只要8.0对应8.0,5.0对应5.0,正常导入到build path就把问题解决了,所以与笔者最后解决问题关系不大,只是解决问题的前提而已.

  • 12
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
This Standard was prepared by the Joint Standards Australia/Standards New Zealand Committee IT-012, Information Systems, Security and Identification Technology and supersedes AS/NZS 4444.1:1999, Information security management, Part 1: Code of practice for information security management. It is identical with ISO/IEC 17799:2000, Information technology—Code of practice for information security management and differs in only very minor editorial details from AS/NZS 4444.1:1999. However the Standard number has been changed to that of the international Standard (ISO/IEC 17799) to minimize any confusion when it is used by organizations internationally. The objective of this Standard is to give recommendations for information security management for use by those who are responsible for initiating, implementing or maintaining security in their organization. It is intended to provide a common basis for developing organizational security standards and effective security management practice and to provide confidence in inter-organizational dealings. This Standard is complementary to AS/NZS 4444.2:2000, Information security management, Part 2: Specification for information security management systems (redesignated in Amendment 2 as AS/NZS 7799.2:2000) and HB 231:2000, Information security risk management guidelines. As this Standard is reproduced from an International Standard, the following applies: (a) In the source text ‘this International Standard’ should read ‘this Australian/New Zealand Standard’. (b) A full point should be substituted for a comma when referring to a decimal marker. Information is a vital asset in any organization. The protection and security of information is of prime importance to many aspects of an organization’s business. It is therefore important that an organization implements a suitable set of controls and procedures to achieve information security and manages them to retain that level of security once it is achieved. This Standard is intended for use by managers and employees who are responsible for initiating, implementing and maintaining information security within their organization and it may be considered as a basis for developing organizational security standards. A comprehensive set of controls comprising the best information security practices currently in use is provided in this Standard. This guidance is intended to be as comprehensive as possible. It is intended to serve as a single reference point for identifying the range of controls needed for most situations where information systems are used in industry and commerce and can therefore be applied by large, medium and small organizations. With increasing electronic networking between organizations there is a clear benefit in having a common reference document for information security management. It enables mutual trust to be established between networked information systems and trading partners and provides a basis for the management of these systems between users and service providers. Not all the controls described in this Standard will be relevant to every situation. It cannot take account of local environmental or technological constraints, or be present in a form that suits every potential user in an organization. Consequently this Standard might need to be supplemented by further guidance. It can be used as a basis from which, for example, a corporate policy or an inter-company trading agreement can be developed. The guidance and recommendations provided throughout this Standard should not be quoted as if they were specifications. In particular, care should be taken to ensure that claims of compliance are not misleading. It has been assumed in the drafting of this Standard that the execution of its recommendations is entrusted to suitably qualified and experienced people.
This error message usually occurs when the JDBC driver for MySQL is not found or not properly configured in your Java application. To fix this issue, you need to make sure that you have the correct JDBC driver for MySQL installed and that the driver is included in your application's classpath. Here are some steps you can follow to resolve this issue: 1. Download the JDBC driver for MySQL from the official website: https://dev.mysql.com/downloads/connector/j/ 2. Extract the downloaded ZIP file and copy the JAR file to a folder in your project directory. 3. Add the JDBC driver JAR file to your project's classpath. You can do this by adding the following line to your project's build file (e.g. pom.xml for Maven): <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.23</version> </dependency> 4. Make sure that you are using the correct JDBC URL for your MySQL database. The format should be like this: jdbc:mysql://localhost:3306/your_database_name Replace "your_database_name" with the actual name of your MySQL database. 5. Check that your MySQL database is running and accessible from your Java application. You can test this by using a MySQL client tool (e.g. MySQL Workbench) to connect to the database using the same credentials that your Java application is using. Once you have verified that the JDBC driver is installed and configured correctly, and that your MySQL database is running and accessible, you should be able to connect to the database from your Java application without any issues.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值