3

我已从 Java 客户端连接 BigQuery,但出现以下异常

BigQuery com.google.cloud.bigquery.BigQueryException:sun.security.validator.ValidatorException:PKIX 路径构建失败:sun..security.provider.certpath.SunCertPathBuilderException:无法找到请求目标的有效证书路径

我在 pom.xml 中使用了以下依赖项

<dependency>
  <groupId>com.google.cloud</groupId>
  <artifactId>google-cloud-bigquery</artifactId>
</dependency>

连接 BigQuery 的 Java 代码

import com.google.cloud.bigquery.BigQuery;

String jsonPath = serviceJsonKey;
String projected = "projected";
GoogleCredentials googleCredentials=null;

try(FileInputStream service = new FileInputStream(jsonPath)){
   if(googleCredentials == null){
     googleCredentials = ServiceAccountCredntials.fromStream(service);
   }
}catch(Exception e){
   e.printStackTrace();
}

BigQuery bigQuery = BigQueryOptions.newBuilder().setCredentials(googleCredentials).setProjectId(projectId);

String tableName = "name of the table";
String dataSetName = "dataSetName";
TableId tableId = TableId.of(dataSetName, TableName);

String query= ("INSERT tablename (name, value) VALUES ('test','test')");
QueryJobConfiguration queryConfig = QueryJobConfiguration.newBuilder(query).build();
try{
   TableResult result = bigQuery.query(queryConfig);
}catch(Exception e){

}
System.out.println("inserted successfully");

使用此代码,我得到了上述错误。我正在使用来自 Google 云的服务 json 密钥,并将其添加到我的运行配置中。

我也尝试从该站点添加证书。它不工作。我试图从我的 java 路径中添加 cacerts 证书,并在我的环境变量中添加了 java home。

没有任何效果。

请帮助我克服这个问题。

提前致谢。

4

1 回答 1

0

尝试将 jsse.enableSNIExtension 属性设置为 true,它对我有帮助

于 2022-02-15T11:52:53.437 回答