Registering the Connector Class

Before connecting to your data, you must register the appropriate class for your application.

The following classes are used to connect the Simba Google BigQuery JDBC Connector to BigQuery data stores:

  • The Driver classes extend java.sql.Driver.
  • The DataSource classes extend javax.sql.DataSource and javax.sql.ConnectionPoolDataSource.

The connector supports the following fully-qualified class names (FQCNs) that are independent of the JDBC version:

  • com.simba.googlebigquery.jdbc.Driver
  • com.simba.googlebigquery.jdbc.DataSource

The following sample code shows how to use the DriverManager class to establish a connection for JDBC 4.2:

private static Connection connectViaDM() throws Exception

{

Connection connection = null;

connection = DriverManager.getConnection(CONNECTION_URL);

return connection;

}

The following sample code shows how to use the DataSource class to establish a connection:

private static Connection connectViaDS() throws Exception

{

Connection connection = null;

DataSource ds = new com.simba.googlebigquery.jdbc.DataSource();

ds.setURL(CONNECTION_URL);

connection = ds.getConnection();

return connection;

}

The following sample code shows how to use service authentication to establish a connection:

private static Connection connectViaDS() throws Exception

{

Connection connection = null;

DataSource ds = new

com.simba.bigquery.jdbc.DataSource();

ds.setURL(CONNECTION_URL);

ds.setProjectId(PROJECT);

ds.setOAuthType(0); // Service Authentication

ds.setOAuthServiceAcctEmail(EMAIL);

ds.setOAuthPvtKeyFile(KEYFILE);

connection = ds.getConnection();

return connection;

}

Note:

When using the DataSource class to establish a connection, all the required properties of CONNECTION_URL should be configured. For service authentication, the properties can be configured separately.