请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

dao出错,好像无法连接数据库

四月 15, 2019 4:19:44 下午 org.springframework.test.context.support.DefaultTestContextBootstrapper getDefaultTestExecutionListenerClassNames
信息: Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
四月 15, 2019 4:19:44 下午 org.springframework.test.context.support.DefaultTestContextBootstrapper getTestExecutionListeners
信息: Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@1e67b872, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@60addb54, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@3f2a3a5, org.springframework.test.context.support.DirtiesContextTestExecutionListener@4cb2c100, org.springframework.test.context.transaction.TransactionalTestExecutionListener@6fb554cc, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@614c5515]
四月 15, 2019 4:19:44 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [spring/spring-dao.xml]
四月 15, 2019 4:19:44 下午 org.springframework.context.support.GenericApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.GenericApplicationContext@7dc7cbad: startup date [Mon Apr 15 16:19:44 CST 2019]; root of context hierarchy
四月 15, 2019 4:19:44 下午 com.mchange.v2.log.MLog
信息: MLog clients using java 1.4+ standard logging.
四月 15, 2019 4:19:44 下午 com.mchange.v2.c3p0.C3P0Registry banner
信息: Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]

Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!

The error may exist in file [D:\workplace\o2o\target\classes\mapper\AreaDao.xml]

The error may involve com.zzh.o2o.dao.AreaDao.queryArea

The error occurred while executing a query

Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!

请教下老师该怎么更正

正在回答

3回答

同学好,我感觉是你用了mysql8而用的是mysql5的驱动。建议在没有类似解决问题的能力之前,还是先用目前市面依然主流的mysql5.x,否则要把c3p0和相关数据库jdbc版本调整到最新,并且后续mysql8在主从同步的grant语句语法也不一样

0 回复 有任何疑惑可以回复我~
  • 提问者 AKIRA_ZZH #1
    老师我查看了下,我的mysql版本就是5.7.21的,然后我看了下5.7和5.5之间好像在连接上有差别,不知道老师录视频的时候mysql的具体版本是多少呢
    回复 有任何疑惑可以回复我~ 2019-04-16 13:05:01
  • 提问者 AKIRA_ZZH #2
    非常感谢!老师我发现了mysql5.7的jdbc配置和mysql5.5是有不同的
    jdbc.driver=com.mysql.cj.jdbc.Driver
    jdbc.url=jdbc:mysql://localhost:3306/o2o?useSSL=false&characterEncoding=utf-8&serverTimezone=UTC
    jdbc.username=root
    jdbc.password=123456
    这个才是5.7的正确jdbc然后在pom.xml里还需要修改mysql的和c3p0的版本
    <dependency>
    	<groupId>mysql</groupId>
    	<artifactId>mysql-connector-java</artifactId>
    	<version>8.0.11</version>
    </dependency>
       <dependency>
        <groupId>com.mchange</groupId>
        <artifactId>c3p0</artifactId>
        <version>0.9.5.4</version>
        </dependency>
    这是我的配置,现在junit已经测试成功了!!!
    回复 有任何疑惑可以回复我~ 2019-04-16 15:19:31
  • 翔仔 回复 提问者 AKIRA_ZZH #3
    赞同学解决问题的能力,我视频里用的是mysql5.7.18的版本
    回复 有任何疑惑可以回复我~ 2019-04-16 23:16:19
提问者 AKIRA_ZZH 2019-04-15 23:53:21

我觉得有可能是我的spring-dao.xml中的配置出了问题

0 回复 有任何疑惑可以回复我~
提问者 AKIRA_ZZH 2019-04-15 23:52:09

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:

### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!

### The error may exist in file [D:\workplace\o2o\target\classes\mapper\AreaDao.xml]

### The error may involve com.zzh.o2o.dao.AreaDao.queryArea

### The error occurred while executing a query

### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!

这个是错误测试的报告,我认为应该是数据库没有连接成功,但是我也不知道哪里出了错误

0 回复 有任何疑惑可以回复我~
  • 你好我是mysql版本是:Server version: 5.7.28-log MySQL Community Server (GPL)
    我按照你改了加了cj和修改的pom还是不行。。你说spring-dao的问题是什么问题呢?
    回复 有任何疑惑可以回复我~ 2020-05-12 02:08:22
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信