异常:com.alibaba.druid.pool.DruidDataSource : create connection SQLException, url: jdbc:sqlserver://

Tch
Tch
Published on 2021-10-26 / 90 Visits
0
0

异常提示

2021-10-26 15:46:20.137  INFO 6656 --- [           main] e.d.AndroidJavaSqlserverApplicationTests : Starting AndroidJavaSqlserverApplicationTests using Java 1.8.0_312 on SH5003147002 with PID 6656 (started by chaotian in C:\workspaces\IDEA\android-java-sqlserver)
2021-10-26 15:46:20.140  INFO 6656 --- [           main] e.d.AndroidJavaSqlserverApplicationTests : No active profile set, falling back to default profiles: default
2021-10-26 15:46:21.315  WARN 6656 --- [           main] o.m.s.mapper.ClassPathMapperScanner      : No MyBatis mapper was found in '[com.example.demo]' package. Please check your configuration.
2021-10-26 15:46:21.795 ERROR 6656 --- [           main] c.a.druid.pool.DruidAbstractDataSource   : maxIdle is deprecated
2021-10-26 15:46:23.055  INFO 6656 --- [           main] e.d.AndroidJavaSqlserverApplicationTests : Started AndroidJavaSqlserverApplicationTests in 3.493 seconds (JVM running for 4.872)
class com.alibaba.druid.pool.DruidDataSource
2021-10-26 15:46:23.539  INFO 6656 --- [           main] com.alibaba.druid.pool.DruidDataSource   : {dataSource-1} inited
2021-10-26 15:46:23.793 ERROR 6656 --- [eate-1058686869] com.alibaba.druid.pool.DruidDataSource   : create connection SQLException, url: jdbc:sqlserver://localhost:1433;DatabaseName=student, errorCode 0, state null
 
java.sql.SQLException: validateConnection false
	at com.alibaba.druid.pool.DruidAbstractDataSource.validateConnection(DruidAbstractDataSource.java:1418) ~[druid-1.2.8.jar:1.2.8]
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1733) ~[druid-1.2.8.jar:1.2.8]
	at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2838) ~[druid-1.2.8.jar:1.2.8]
Caused by: java.lang.NullPointerException: null
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.ensureSQLSyntax(SQLServerStatement.java:778) ~[mssql-jdbc-9.2.1.jre8.jar:na]
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:822) ~[mssql-jdbc-9.2.1.jre8.jar:na]
	at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:767) ~[mssql-jdbc-9.2.1.jre8.jar:na]
	at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7418) ~[mssql-jdbc-9.2.1.jre8.jar:na]
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:3272) ~[mssql-jdbc-9.2.1.jre8.jar:na]
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:247) ~[mssql-jdbc-9.2.1.jre8.jar:na]
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:222) ~[mssql-jdbc-9.2.1.jre8.jar:na]
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.execute(SQLServerStatement.java:743) ~[mssql-jdbc-9.2.1.jre8.jar:na]
	at com.alibaba.druid.pool.vendor.MSSQLValidConnectionChecker.isValidConnection(MSSQLValidConnectionChecker.java:50) ~[druid-1.2.8.jar:1.2.8]
	at com.alibaba.druid.pool.DruidAbstractDataSource.validateConnection(DruidAbstractDataSource.java:1398) ~[druid-1.2.8.jar:1.2.8]
	... 2 common frames omitted

出现场景: springboot + druid + sqlserver

在执行以下测试的时候就会报错

原因:druid的版本问题,具体未知

解决办法:修改druid的版本

 可以看到druid的版本已经到了1.2.8.而我就是用的这个版本才报的错。在网上找的方法都是让改到1.1.10,经测试确实是可以。通过对每一个版本的测试,1.2.5版本是可以解决问题的,版本再新就不行了。

如图,改了druid的版本后这条路已经通了

参考:https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/86555162 


Comment