Connecting your Application using Java

Learn how to connect your Java application to Oracle NoSQL Database Cloud Service.

Your application connects to Oracle NoSQL Database Cloud Service by specifying credentials and a target region for the connection. See Acquiring Credentials for the required credentials information.

You provide credentials in your application using either:
  • An API that allows you to directly provide the credentials, or
  • A configuration file

Connecting Using API

/* Use the SignatureProvider to supply your credentials to NoSQL Database.
 * By default, the SignatureProvider will read your OCI configuration file 
 * from the default location, ~/.oci/config. See SignatureProvider for 
 * additional options for reading configurations in other ways.*/
SignatureProvider sp = new SignatureProvider(
 tenantId,     // a string, OCID
 userId,       // a string, OCID
 fingerprint , // a string
 privateKey,   // a string, content of private key
 passPhrase    // optional, char[]
);
//Create an handle to access the cloud service in the us-ashburn-1 region.
NoSQLHandleConfig config = new NoSQLHandleConfig(Region.US_ASHBURN_1);
config.setAuthorizationProvider(sp);
NoSQLHandle handle = NoSQLHandleFactory.createNoSQLHandle(config);

//At this point, your handle is set up to perform data operations.

Connecting Using a Configuration File

/* Use the SignatureProvider to supply your credentials to NoSQL Database.
 * By default, the SignatureProvider will read your OCI configuration file 
 * from the default location, ~/.oci/config. See SignatureProvider for 
 * additional options for reading configurations in other ways. */
SignatureProvider sp = new SignatureProvider();

//Create an handle to access the cloud service in the us-ashburn-1 region.
NoSQLHandleConfig config = new NoSQLHandleConfig(Region.US_ASHBURN_1);
config.setAuthorizationProvider(sp);
NoSQLHandle handle = NoSQLHandleFactory.createNoSQLHandle(config);

//At this point, your handle is set up to perform data operations.