异常提示 {#%E5%BC%82%E5%B8%B8%E6%8F%90%E7%A4%BA}
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** {#%E5%87%BA%E7%8E%B0%E5%9C%BA%E6%99%AF%3A-springboot-%2B-druid-%2B-sqlserver}
在执行以下测试的时候就会报错
原因:druid的版本问题,具体未知 {#%E5%8E%9F%E5%9B%A0%EF%BC%9Adruid%E7%9A%84%E7%89%88%E6%9C%AC%E9%97%AE%E9%A2%98%EF%BC%8C%E5%85%B7%E4%BD%93%E6%9C%AA%E7%9F%A5}
解决办法:修改druid的版本 {#%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95%EF%BC%9A%E4%BF%AE%E6%94%B9druid%E7%9A%84%E7%89%88%E6%9C%AC}
可以看到druid的版本已经到了1.2.8.而我就是用的这个版本才报的错。在网上找的方法都是让改到1.1.10,经测试确实是可以。通过对每一个版本的测试,1.2.5版本是可以解决问题的,版本再新就不行了。
如图,改了druid的版本后这条路已经通了