赞
踩
这里显示我们,要在后缀加上一个属性 这里默认设置为false
Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: “Encrypt”属性设置为“true”且 “trustServerCertificate”属性设置为“false”,但驱动程序无法使用安全套接字层 (SSL) 加密与 SQL Server 建立安全连接:错误:PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target。 ClientConnectionId:f8eb2dc2-65b1-4ea6-826a-d3350235e243
- package com.xxx.wxjsxy;
-
- import java.sql.*;
-
- public class Jdbc {
-
- public static void main(String[] args) throws SQLException {
- Connection ct=null;
- Statement sm=null;
- ResultSet rs=null;
- int a=0;
- try {
- String url = "jdbc:sqlserver://localhost:1433;DatabaseName=bs_s1";
- // 连接数据库-forName:返回与带有给定字符串名的类或接口相关联的 Class 对象
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- // 得到连接-getConnection:建立到给定数据库 URL 的连接
- ct = DriverManager.getConnection(url,
- "sa", "123456");
- // 创建Statement-将 SQL 语句发送到数据库
- sm = ct.createStatement();
- rs = sm.executeQuery("select * from users");
- while(rs.next()){
- System.out.println(rs.getInt("userID")+","+rs.getString("userName")+","+rs.getString("passwd"));
- }
- } catch (ClassNotFoundException e) {
- // TODO: handle exception
- System.out.println("error loading driver:" + e);
- }
- if (rs!=null)
- rs.close();
- if (sm!=null) {
- sm.close();
- }
- if (ct!=null) {
- ct.close();
- }
-
- }
-
- }
-
这样写就会出现问题,因为默认是false
后缀加上;trustServerCertificate=true
这样就成功了
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。