一直连接不上数据库,然而在本地通过navicat却能连接上

Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server.)
The error may exist in mappers/BizzStepMapper.xml
The error may involve utry.iusher.dao.BizzStepMapper.selectByBizzId
The error occurred while executing a query
Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server.)] with root cause
java.lang.NullPointerException
at com.mysql.jdbc.ConnectionImpl.getServerCharacterEncoding(ConnectionImpl.java:3303)
at com.mysql.jdbc.MysqlIO.sendConnectionAttributes(MysqlIO.java:1987)

解决:
首先检查配置文件,比如jdbc.properties。这里注意里面不能有空格

如果配置文件没有问题多半就是驱动的问题。

mysql6以后的版本驱动包版本和驱动配置变了

mysql6以前版本配置:
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/taotao?characterEncoding=utf-8
jdbc.username=root
jdbc.password=root
驱动包版本:
<dependency>
	<groupId>mysql</groupId>
	<artifactId>mysql-connector-java</artifactId>
	<version>5.1.32</version>
</dependency>
mysql6以后版本配置:
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://192.168.25.124:3306/taotao?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useSSL=false&verifyServerCertificate=false&autoReconnct=true&autoReconnectForPools=true&allowMultiQueries=true
jdbc.username=root
jdbc.password=root
驱动包版本:
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.13</version>
</dependency>

特别注意:

驱动包中的版本号要与你mysql数据库的版本一致

你可能感兴趣的:(后端,遇到过的小问题,数据库)