问题描述

在运用JDBC连接数据库时,用的是C3P0数据源,出现Connections could not be acquired from the underlying database!这个异常

话不多说,先上代码

public class C3P0Test {@Test//测试JDBC模板public void test1() throws PropertyVetoException {//设置数据源ComboPooledDataSource dataSource = new ComboPooledDataSource();dataSource.setDriverClass("com.mysql.cj.jdbc.Driver");dataSource.setJdbcUrl("jdbc:mysql://localhost:3308/db01");dataSource.setUser("root");dataSource.setPassword("lyj20010327");JdbcTemplate jdbcTemplate = new JdbcTemplate();//设置数据源   知道数据源在哪jdbcTemplate.setDataSource(dataSource);//执行操作int data = jdbcTemplate.update("insert into dept value(?,?,?)","10000","Asdnasc","db01");System.out.println(data);}}

原因分析:

很多原因都会使连接数据库出错,我列出以下几个可能出现的原因

  1. 驱动Jar包版本与注册驱动的类不匹配。
  2. 数据库连接地址有误。
  3. 数据库账户密码是否输入正确。
  4. 数据库,表,字段是否对应。
  5. 项目是否引入驱动包。

解决方案:

对应的解决方案:

一.驱动包与注册驱动类的匹配关系,一般是5版本与8版本

  1. 5版本的驱动包:注册驱动类为 com.mysql.jdbc.Driver。
  2. 8版本的驱动包:注册驱动类为 com.mysql.cj.jdbc.Driver。

二.时区配置问题,一般存在于8版本的驱动包

如果你是8版本的驱动包,连接数据库时需要配置一个时区,在路径url后面加上?serverTimezone=GMT

问题完美解决!

Connections could not be acquired from the underlying database异常,已解决。相关推荐

  1. SSM:出现Connections could not be acquired from the underlying database异常的解决

    QUESTION:SSM:出现Connections could not be acquired from the underlying database异常的解决 ANSWER: 近期在学习ssm框 ...

  2. 【JDBC 报错】Connections could not be acquired from the underlying database!

    项目启动报错: 1 [2016-07-13 10:04:15,074] ERROR org.apache.ibatis.executor.BaseExecutor Could not get a da ...

  3. 解决:Connections could not be acquired from the underlying database!(mysql)

    这两天一直有这个bug出现,记录一下解决方案和总结. 解决方案: 1.驱动配置错误(本人的bug) 2.数据库连接地址错误 3.账号密码错误 4.数据库未启动或者无权访问,如没有联网的情况下 5.版本 ...

  4. Hibernate 错误记录Connections could not be acquired from the underlying database!

    Hibernate 错误记录Connections could not be acquired from the underlying database! 错误详情 网上的解决办法 我的错误解决 错误 ...

  5. 新手解决Connections could not be acquired from the underlying database!Java代码上传到服务器连接不上数据库

    本人刚入门Java,最近在开发一个项目,由于项目中有些问题需要与客户沟通.就想着把程序先上传到服务器上,先是上传到我之前用的服务器,服务器没有配置Java 环境.我自己配置好环境后把编译后代码上传上去 ...

  6. 服务器Connections could not be acquired from the underlying database错误

    在写一个ssm框架的demo中,在spring整合mybatis后开始运行时,服务器出现了一个报错: org.springframework.web.util.NestedServletExcepti ...

  7. Oracle 换库时发生 Connections could not be acquired from the underlying database

    在进行数据库切换发生如下错误: Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionExce ...

  8. 解决:Connections could not be acquired from the underlying database!

    问题 Connections could not be acquired from the underlying database! 出错,最后发现我的mysql版本是8.x 导入的依赖是5.x版本 ...

  9. 连接MySQL: Connections could not be acquired from the underlying database

    项目场景: ssm项目连接mysql 8.0 报错:Connections could not be acquired from the underlying database! 问题描述: ### ...

最新文章

  1. 利用交换机解决局域网ARP问题(51CTO博客出书活动)
  2. HBase解决海量图片存储方案
  3. WebGL Shader 环境搭建
  4. python模块讲解_python模块详解 | filecmp
  5. SQL——一种简单的基于角色控制的权限管理数据库设计DEMO
  6. wxWidgets:wxTaskBarIcon类用法
  7. BZOJ 2818——Gcd
  8. codeforces George and Job
  9. 转载 foreach比递归效率低
  10. linux服务器进虚拟机,初次登录 Linux 服务器马上要做的 9 件事|Linux 中国
  11. java皮肤库的框架_VC 添加皮肤库
  12. 阿里发布的规约插件,细节都在这里
  13. 清华大学数学与计算机学院院长,王跃宣(清华大学教授)_百度百科
  14. MySQL-5.5.32 配置文件优化详解
  15. Monitor(管程)是什么意思?Java中Monitor(管程)的介绍
  16. 浅析新媒体运营工作内容
  17. Input框内容改变触发事件,实现表格动态模糊查询
  18. 微信小程序的wxml实现复杂运算或者数据处理
  19. linux中cp命令详解
  20. maven打包maven-shade-plugin报错Non-parseable POM解决方法

热门文章

  1. 【CSDN AI周刊】第14期 | 吴恩达离职百度 CNN之父清华演讲
  2. 2019十佳DevOps工具,你用了几个?
  3. 2.4亿单身人口新浪潮,小红书品牌3步抓住流量风口
  4. Spring Aop(四)——基于Aspectj注解的Advice介绍
  5. GDSII format
  6. 第三次作业 - 结对项目1
  7. mariadb与mysql
  8. Flutter基础-(3)Widget之文本Text
  9. stm32f103c8t6+esp8266在WiFi下通过手机控制外设
  10. 5800计算机交点法程序大全,FX5800计算器交点法正反算程序加入高程及隧道超欠挖...