The exception information is as follows:
java.sql.SQLException: validateConnection false
at com.alibaba.druid.pool.DruidAbstractDataSource.validateConnection(DruidAbstractDataSource.java:1418)
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1733)
at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2801)
Caused by: java.lang.NullPointerException: null
at com.alibaba.druid.wall.WallProvider.checkInternal(WallProvider.java:707)
at com.alibaba.druid.wall.WallProvider.check(WallProvider.java:584)
at com.alibaba.druid.wall.WallFilter.checkInternal(WallFilter.java:826)
at com.alibaba.druid.wall.WallFilter.check(WallFilter.java:821)
at com.alibaba.druid.wall.WallFilter.statement_execute(WallFilter.java:454)
at com.alibaba.druid.filter.FilterChainImpl.statement_execute(FilterChainImpl.java:3008)
at com.alibaba.druid.filter.FilterAdapter.statement_execute(FilterAdapter.java:2484)
at com.alibaba.druid.filter.FilterEventAdapter.statement_execute(FilterEventAdapter.java:188)
at com.alibaba.druid.filter.FilterChainImpl.statement_execute(FilterChainImpl.java:3008)
at com.alibaba.druid.proxy.jdbc.StatementProxyImpl.execute(StatementProxyImpl.java:147)
at com.alibaba.druid.pool.vendor.MSSQLValidConnectionChecker.isValidConnection(MSSQLValidConnectionChecker.java:50)
at com.alibaba.druid.pool.DruidAbstractDataSource.validateConnection(DruidAbstractDataSource.java:1398)
Follow this method: com.alibaba.druid.pool.druidabstractdatasource.validateconnection
result = validConnectionChecker.isValidConnection(conn, validationQuery, validationQueryTimeout);
Find the exception of this line of code and enter this method
Find the method of this implementation class (because it is SQL server)
public boolean isValidConnection(final Connection c, String validateQuery, int validationQueryTimeout) throws Exception {
if (c.isClosed()) {
return false;
}
Statement stmt = null;
try {
stmt = c.createStatement();
if (validationQueryTimeout > 0) {
stmt.setQueryTimeout(validationQueryTimeout);
}
stmt.execute(validateQuery);
return true;
} catch (SQLException e) {
throw e;
} finally {
JdbcUtils.close(stmt);
}
}
Finally, it is found that the method parameter validatequery is null, so a null pointer is reported. Let’s go back and see why it is null
protected volatile String validationQuery = DEFAULT_VALIDATION_QUERY;
Class defines that validationquery is equal to default_ VALIDATION_ Query, and default_ VALIDATION_ Query initialization is defined as null. In fact, this parameter comes from the springboot configuration file
Add the following configuration in the springboot data source configuration file:
druid:
validation-query: SELECT 1
Just do it!
PS, data source configuration:
driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
url: jdbc:sqlserver://IP:PORT;DatabaseName=database name
username: username
password: password
druid:
validation-query: SELECT 1
Read More:
- Configuration of springboot + Druid connection pool
- Java database Druid error: com.alibaba.druid.pool.DruidDataSource error
- [How to Solve]Repeated column in mapping for entity,should be mapped with insert=“false“ update=“false“
- [Solved] com.alibaba.druid.filter.FilterManager : load filter error, filter not found : sl4j
- [Solved] Mybatis integrates PageHelper and uses sqlserver paging error
- [Solved] Springboot connect MySQL error: errorcode 0, state 08s01
- [Solved] springboot Project Run Error: HikariPool-1 – Exception during pool initialization.
- SpringBoot+Swagger Error: 403 Forbidden [How to Solve]
- Springboot error about swagger startup [How to Solve]
- NULL value exception occurs when freemarker renders the page globally in the springboot project
- [Solved] SpringBoot Error: org.springframework.http.converter.HttpMessageNotReadableException
- Springboot Project Error: Failed to execute goal org.apache.maven.plugins
- [Solved] Springboot Project Startup Error: Unable to Identify bootstrap.yml Configuration
- [Solved] Springboot Project Error: Mail server connection failed;
- Springboot2.6X version integrate knife4j error [How to Solve]
- [Solved] Springboot error: Could Not Found xxmapper
- The problem of date format conversion between springboot and front end
- [Solved] Springboot Error: Error creating bean with name ‘dataSource‘ defined in class path resource
- [Solved] Springboot uses redis to add LocaldateTime Java 8 error
- Springboot2.6.X configurate swagger error [How to Solve]