1. jtds 1.3.2+ 驱动下载
Releases · milesibastos/jTDS · GitHub
项目resources下新建lib目录
拷贝“jtds-1.3.2.jar”到lib目录,pom引用
<properties>
<java.version>1.8</java.version>
<!-- DB驱动 -->
<postgresql.version>42.2.6</postgresql.version>
<ojdbc6.version>11.2.0.3</ojdbc6.version>
<sqljdbc4.version>4.0</sqljdbc4.version>
<jtds.version>1.3.2</jtds.version>
<mysql-connector-java.version>8.0.20</mysql-connector-java.version>
</properties>
<!-- 数据库驱动 -->
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql-connector-java.version}</version>
<scope>runtime</scope>
</dependency>
<!-- sqlserver-->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>${sqljdbc4.version}</version>
<scope>runtime</scope>
</dependency>
<!--<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>${jtds.version}</version>
<scope>runtime</scope>
</dependency>-->
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>${jtds.version}</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/lib/jtds-1.3.2.jar</systemPath>
</dependency>
<!-- oracle驱动 -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>${ojdbc6.version}</version>
<scope>runtime</scope>
</dependency>
<!-- postgresql驱动 -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
<scope>runtime</scope>
</dependency>
打包jar,"spring-boot-maven-plugin"红色的时候,在本地找到“org.springframework.boot/spring-boot-maven-plugin”仓库地址,版本号,version显示指定即可。
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.3.5.RELEASE</version>
<configuration>
<mainClass>com.example.demo.ReportApplication</mainClass>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
</build>
2.拷贝“jtds-1.3.2-dist.zip”解压的SSO x64中“ntlmauth.dll”放到“java.library.path”中,jdk的bin(注意不是lib),你可以运行打印一下System.getPropery("java.library.path")。
3. 启动sqllocaldb
查看命名管道信息
sqllocaldb i ProjectsV13
输出
springboot application.yml配置
server:
port: 8085
spring:
#配置静态资源
mvc:
static-path-pattern: /**
resource:
static-locations: classpath:/static/
#配置数据库
datasource:
# username: root
# password: 123456
# driver-class-name: com.mysql.cj.jdbc.Driver
# driver-class-name: com.mysql.jdbc.Driver
# url: jdbc:mysql://${MYSQL-HOST:localhost}:${MYSQL-PORT:3306}/${MYSQL-DB:xlreport}?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&allowPublicKeyRetrieval=true
# driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
# url: jdbc:sqlserver://localhost:1433;DatabaseName=xlreport
driver-class-name: net.sourceforge.jtds.jdbc.Driver
url: jdbc:jtds:sqlserver://./xlreport;instance=LOCALDB#C34AD3E5;namedPipe=true;Trusted_Connection=true;
hikari:
connection-test-query: SELECT 1
其中:
hikari:
connection-test-query: SELECT 1
必须要配置,否则报IsValid 错误。
url中:
//./${DB_NAME};instance=LOCALDB#${NamedPipeID},NamedPipeID为“sqllocaldb i ProjectsV13下面的相同的ID”,如果报“指定的文件不存在”,说明localdb停止了,需要重新打开,注意这里的管道ID会变化。