当前位置:   article > 正文

Cannot find class: com.mysql.cj.jdbc.driver 找不到类

cannot find class: com.mysql.cj.jdbc.driver

目录

一、报错代码

二、错误原因

 三、运行结果(成功) 

四、总结


一、报错代码

        主要错误就是,找不到我们的 MySql 的驱动类了,所以就会出现以下错误

  1. Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: com.mysql.cj.jdbc.driver
  2. at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
  3. at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149)
  4. at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)
  5. at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:76)
  6. at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:87)
  7. at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:152)
  8. at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85)
  9. at com.sun.proxy.$Proxy9.findById(Unknown Source)
  10. at org.nf.Main.main(Main.java:37)
  11. Caused by: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: com.mysql.cj.jdbc.driver
  12. at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.initializeDriver(UnpooledDataSource.java:244)
  13. at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:223)
  14. at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:219)
  15. at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:95)
  16. at org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:432)
  17. at org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:89)
  18. at org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:139)
  19. at org.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:61)
  20. at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:337)
  21. at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:86)
  22. at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)
  23. at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325)
  24. at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
  25. at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
  26. at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:89)
  27. at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)
  28. ... 7 more
  29. Process finished with exit code 1

二、错误原因

        原来是太粗心了,把 Driver 写成了小写的 driver

改正

        因为手写打的太快了,所以就打成了小写的,我们可以发现 idea 还是很智能的,我们改回大写还有提示的


 三、运行结果(成功) 


四、总结

        这次是因为大小写的问题报的错,找了好久才发现是写成小写的,顺便就做个笔记,让自己印象深刻一点,下次错了就能够想起来是怎么错的了。还有就是以后要更加细心才行,这些都是很小的失误,但往往就是小失误更加让人头疼。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/618461
推荐阅读
相关标签
  

闽ICP备14008679号