Could not load JDBC driver class [com.mysql.jdbc.Driver]
时间:2022-07-22
本文章向大家介绍Could not load JDBC driver class [com.mysql.jdbc.Driver],主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
我使用Spring JDBC编程时,遇到一个错误消息:Could not load JDBC driver class [com.mysql.jdbc.Driver]
完整的错误为:
Jul 27, 2020 12:22:26 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@5b80350b: startup date [Mon Jul 27 12:22:26 CST 2020]; root of context hierarchy
Jul 27, 2020 12:22:26 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [Beans.xml]
Jul 27, 2020 12:22:26 PM org.springframework.context.support.ClassPathXmlApplicationContext refresh
WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [Beans.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [com.mysql.jdbc.Driver]
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [Beans.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [com.mysql.jdbc.Driver]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1650)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1357)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:758)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)
at com.sap.MainApp.main(MainApp.java:10)
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [com.mysql.jdbc.Driver]
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:123)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:77)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1646)
... 13 more
解决方法:
下载MySQL Connector/J(the official JDBC driver for MySQL). https://dev.mysql.com/downloads/connector/j/
将下载的mysql-connector-java.jar添加到Java build path后问题解决:
使用mySQL client命令行可以看到之前用Java JDBC插入的数据库条目:
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
- Sass 基础(四)
- Bash 脚本:正则表达式基础篇
- 补丁管理:不要以持续运行时间为自豪
- 微信小程序再次深夜放大招!竟然可以玩起直播来了?
- 上海设专项资金支持人工智能创新发展
- 监管下发145号文摸底互联网平台与交易所合作
- 条码支付确立规范引导金融创新趋利避害
- 百度Apollo自动驾驶组“国家队”,全线产品将在CES首度亮相
- Sass 基础(三)
- 2018年——霍金怎么样谈未来人工智能,地球还有多少时间
- Linux探秘之用户态与内核态
- 微信小游戏重磅上线,H5游戏和页游迎来新天地?
- 名为“闪电比特币”Lightning Bitcoin,LBTC的新型比特币硬叉被释放
- IDHub亮相区块链行业巅峰盛宴 分享网络生活的“进化论”
- MySQL 教程
- MySQL 安装
- MySQL 管理与配置
- MySQL PHP 语法
- MySQL 连接
- MySQL 创建数据库
- MySQL 删除数据库
- MySQL 选择数据库
- MySQL 数据类型
- MySQL 创建数据表
- MySQL 删除数据表
- MySQL 插入数据
- MySQL 查询数据
- MySQL where 子句
- MySQL UPDATE 查询
- MySQL DELETE 语句
- MySQL LIKE 子句
- mysql order by
- Mysql Join的使用
- MySQL NULL 值处理
- MySQL 正则表达式
- MySQL 事务
- MySQL ALTER命令
- MySQL 索引
- MySQL 临时表
- MySQL 复制表
- 查看MySQL 元数据
- MySQL 序列 AUTO_INCREMENT
- MySQL 处理重复数据
- MySQL 及 SQL 注入
- MySQL 导出数据
- MySQL 导入数据
- MYSQL 函数大全
- MySQL Group By 实例讲解
- MySQL Max()函数实例讲解
- mysql count函数实例
- MYSQL UNION和UNION ALL实例
- MySQL IN 用法
- MySQL between and 实例讲解
- mysql主从复制
- 蚁群算法详解
- Redis的使用--(一)集群的搭建
- Docker(二)基础使用
- Spring Boot实现加载自定义配置文件
- SpringBoot整合Dubbo
- SpringBoot统计实时在线人数
- 人工智能之Python人脸识别技术--face_recognition模块
- Redis的使用--(二)与Spring的整合
- Milvus 实战|利用 Milvus 搭建基于图的推荐系统
- k8s基本使用
- 淮师2017校园新闻爬取&&WordCloud年度词云分析
- 13 | Tornado源码分析:BaseIOStream 对象(下)
- 谈谈线程
- springboot整合定时框架-Elastic-job-lite