I have connected BigQuery from Java client but am getting the below exception

BigQuery com.google.cloud.bigquery.BigQueryException: sun.security.validator.ValidatorException: PKIX path building failed: sun..security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

I have used the below dependency in the pom.xml

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

The Java code to connect with BigQuery

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");

With this code am getting the above-mentioned error. I am using the service json key from Google cloud and I have added it to my run configuration.

I tried to add the certificated from the site also. It is not working. I have tried to add the cacerts certs from my java path and added the java home in my environment variables also.

Nothing works.

please help me to overcome this issue.

Thanks in advance.

1

There are 1 answers

1
Nikita Butylo On

Try setting jsse.enableSNIExtension property to true, it helped for me