老问题,数据库连接不上,求解决!!!
尝试了所有评论中的方法,依然连接不上!!!
1.修改jdbc.properties
jdbc.driver=com.mysql.cj.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/seckill?useUnicode=true&characterEncoding=uft8&serverTimezone=UTC&useSSL=false jdbc.user=root jdbc.password=***
同时修改spring-dao.xml;另将超时时间改为0,无限等待
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="${jdbc.driver}"/> <property name="jdbcUrl" value="${jdbc.url}"/> <property name="user" value="${jdbc.user}"/> <property name="password" value="${jdbc.password}"/> <!-- c3p0连接池的私有属性 --> <!-- 数据库最大连接对象 默认:15 --> <property name="maxPoolSize" value="30"/> <!-- 数据库最小连接对象 默认:3 --> <property name="minPoolSize" value="10"/> <!-- 关闭连接后不自动commit 默认:false --> <property name="autoCommitOnClose" value="false"/> <!-- 获取连接超时时间 默认:0,表示无限等待--> <property name="checkoutTimeout" value="0"/> <!-- 当获取连接失败时重试次数 --> <property name="acquireRetryAttempts" value="2"/> </bean>
3.修改pom.xml中各项配置版本
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.11</version> <scope>runtime</scope> </dependency> <dependency> <groupId>com.mchange</groupId> <artifactId>c3p0</artifactId> <version>0.9.5.2</version> </dependency>
依然报错
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!
### The error may exist in file [F:\seckill\target\classes\mapper\SeckillDao.xml]
### The error may involve org.seckill.dao.SeckillDao.queryById
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!
已经无力了,求大神解决!!!