springboot 连接 sqlserver

spring:
  datasource:
    driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
    url: jdbc:sqlserver://IP:1433;databaseName=数据库名;trustServerCertificate=true
    username: 账号
    password: 密码
mybatis:
  mapper-locations: classpath:mapper/*.xml
  type-aliases-package: com.jinawei.sanbian.entity   实体类包
  configuration:
    map-underscore-to-camel-case: true
server:
  port: 8888
mybatis-plus:
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

com.microsoft.sqlserver.jdbc.SQLServerException: 驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“The server selected protocol version TLS10 is not accepted by client preferences [TLS13, TLS12]”。

修改java.security文件 

jdk.tls.disabledAlgorithms=SSLv3, TLSv1, TLSv1.1, RC4, DES, MD5withRSA, \
    DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \
    include jdk.disabled.namedCurves

把其中的 TLSv1, TLSv1.1,3DES_EDE_CBC  删除保存

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
连接 SQL Server 数据库的方式与连接其他数据库的方式基本相同,需要在 pom.xml 文件中添加 SQL Server JDBC 驱动的依赖,然后在 application.properties 文件中配置数据库连接信息。下面是连接 SQL Server 数据库的示例代码: 1. 添加 SQL Server JDBC 驱动依赖 在 pom.xml 文件中添加以下依赖: ```xml <dependency> <groupId>com.microsoft.sqlserver</groupId> <artifactId>mssql-jdbc</artifactId> <version>8.2.2.jre11</version> </dependency> ``` 2. 在 application.properties 文件中配置数据库连接信息 ```properties # 数据库连接信息 spring.datasource.url=jdbc:sqlserver://localhost:1433;DatabaseName=test spring.datasource.username=sa spring.datasource.password=123456 spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver ``` 其中,url 中的 localhost:1433 表示 SQL Server 数据库所在的服务器及端口号,DatabaseName=test 表示要连接的数据库名,username 和 password 分别是数据库的用户名和密码,driver-class-name 是 SQL Server JDBC 驱动的类名。 3. 在代码中使用 JdbcTemplate 访问数据库 ```java @Service public class UserService { @Autowired private JdbcTemplate jdbcTemplate; public List<User> findAll() { String sql = "SELECT id, name, age FROM users"; return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(User.class)); } public void save(User user) { String sql = "INSERT INTO users(name, age) VALUES(?, ?)"; jdbcTemplate.update(sql, user.getName(), user.getAge()); } // ... } ``` 以上代码示例中,通过 JdbcTemplate 对象来执行 SQL 语句,具体的 SQL 语句可以根据实际情况进行修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值