Caused by: java.sql.SQLException: Trying to connect with ssl, but ssl not enabled in the server
其实这个问题是意外发现的,前面一篇博客因为数据库配置的最大连接数只有200导致连接失败,在尝试解决问题的时候,看到有人说可以修改springboot配置文件application.yml文件中的datasources的url中的useSSL=false 为useSSL=true,来解决连接的问题,病急乱投医啊,试了试就出现了下面的问题咯~~~
2021-01-22 07:54:03.920 [main] ERROR org.apache.tomcat.jdbc.pool.ConnectionPool - Unable to create initial connections of pool.
java.sql.SQLException: Trying to connect with ssl, but ssl not enabled in the server
at org.mariadb.jdbc.internal.util.ExceptionMapper.get(ExceptionMapper.java:136)
at org.mariadb.jdbc.internal.util.ExceptionMapper.throwException(ExceptionMapper.java:69)
at org.mariadb.jdbc.Driver.connect(Driver.java:109)
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:310)
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:203)
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:735)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:667)
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:482)
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:154)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:118)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:107)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:131)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:325)
at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:365)
at org.springframework.boot.autoconfigure.orm.jpa.DatabaseLookup.getDatabase(DatabaseLookup.java:72)
at org.springframework.boot.autoconfigure.orm.jpa.JpaProperties.determineDatabase(JpaProperties.java:139)
at org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.jpaVendorAdapter(JpaBaseConfiguration.java:105)
at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration$$EnhancerBySpringCGLIB$$bb232614.CGLIB$jpaVendorAdapter$4(<generated>)
。。。 。。。
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Trying to connect with ssl, but ssl not enabled in the server
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:325)
... 69 common frames omitted
Caused by: java.sql.SQLException: Trying to connect with ssl, but ssl not enabled in the server
at org.mariadb.jdbc.internal.util.ExceptionMapper.get(ExceptionMapper.java:136)
at org.mariadb.jdbc.internal.util.ExceptionMapper.throwException(ExceptionMapper.java:69)
at org.mariadb.jdbc.Driver.connect(Driver.java:109)
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:310)
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:203)
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:735)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:667)
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:482)
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:154)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:118)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:107)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:131)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
... 70 common frames omitted
Caused by: org.mariadb.jdbc.internal.util.dao.QueryException: Trying to connect with ssl, but ssl not enabled in the server
at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.handleConnectionPhases(AbstractConnectProtocol.java:462)
at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.connect(AbstractConnectProtocol.java:369)
at org.mariadb.jdbc.internal.protocol.AbstractConnectProtocol.connectWithoutProxy(AbstractConnectProtocol.java:755)
at org.mariadb.jdbc.internal.util.Utils.retrieveProxy(Utils.java:468)
at org.mariadb.jdbc.Driver.connect(Driver.java:104)
... 81 common frames omitted
当然啦,最后问题的真正原因还是找到了,跟useSSL=false这个参数是没有任何关系的,尽管走了弯路,但是毕竟实践出真知嘛,不亏不亏~~~
如:
url: jdbc:mariadb://127.0.0.1:3306/iot?createDatabaseIfNotExist=true&useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&autoReconnect=true&failOverReadOnly=false
C3P0连接池配置一些参数
参数名称 | 参数说明 |
---|---|
user | 数据库用户名(用于连接数据库) |
password | 用户密码(用于连接数据库) |
useUnicode | 是否使用Unicode字符集,如果参数characterEncoding设置为gb2312或gbk,本参数值必须设置为true |
characterEncoding | 当useUnicode设置为true时,指定字符编码。比如可设置为gb2312或gbk |
autoReconnect | 当数据库连接异常中断时,是否自动重新连接? |
autoReconnectForPools | 是否使用针对数据库连接池的重连策略 |
failOverReadOnly | 自动重连成功后,连接是否设置为只读? |
maxReconnects | autoReconnect设置为true时,重试连接的次数 |
initialTimeout | autoReconnect设置为true时,两次重连之间的时间间隔,单位:秒 |
connectTimeout | 和数据库服务器建立socket连接时的超时,单位:毫秒。 0表示永不超时,适用于JDK 1.4及更高版本 |
socketTimeout | socket操作(读写)超时,单位:毫秒。 0表示永不超时 |