javaspring-bootjdbcgoogle-bigqueryspring-cloud-gcp-bigquery

Spring boot BigQuery datasource connection


I am trying to connect BigQuery from Spring boot using Simba jdbc driver but I am getting below exception. Any input is appreciated. I am not sure why spring-boot is looking for a certifcate. I am able to connect with simple java main class, But I am getting this error with Spring boot only.

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getDataSource' defined in class path resource [com/test/demo/services/config/DBConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.simba.googlebigquery.jdbc42.DataSource]: Factory method 'getDataSource' threw exception; nested exception is java.sql.SQLException: [Simba]BigQueryJDBCDriver HttpTransport IO error : PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target.

DataSource ds = new com.simba.googlebigquery.jdbc42.DataSource();
Connection connection = null;
ds.setURL(
    "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;ProjectId=project)id;OAuthType=0;OAuthServiceAcctEmail=serviceAccountEmail;OAuthPvtKeyPath=p12CertPath;");

ds.setProjectId("projectId");
// ds.setOAuthType(0);

// connection = ds.getConnection();
connection = ds.getConnection();

Solution

  • Remove the extra spaces from your JDBC URL, it looks like they are interfering with mandatory OAuthPvtKeyPath, OAuthServiceAcctEmail parameters:

    jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;ProjectId=<Your Project ID>;OAuthType=0;OAuthServiceAcctEmail=<Your Email>;OAuthPvtKeyPath=<Path To Cert>;