Establishing a Connection
Creating a JDBC Data Source
You can create a JDBC data source to connect from your Java application. Creating a JDBC data source based on the CData JDBC Driver for Couchbase consists of three basic steps:
- Add the driver JAR file to the classpath. The JAR file is located in the lib subfolder of the installation directory. Note that the .lic file must be located in the same folder as the JAR file.
- Provide the driver class. For example:
- Provide the JDBC URL. For example:
jdbc:couchbase:User='myusername';Password='mypassword';Server='http://couchbase40' or jdbc:cdata:couchbase:User='myusername';Password='mypassword';Server='http://couchbase40'
The second format above can be used whenever there is a conflict in your application between drivers using the same URL format to ensure you are using the CData driver. The URL must start with either "jdbc:couchbase:" or "jdbc:cdata:couchbase:" and can include any of the connection properties in name-value pairs separated with semicolons.
Connecting to Couchbase
To connect to data, set the Server property to the hostname or IP address of the Couchbase server(s) you are authenticating to. If your Couchbase server is configured to use SSL, you can enable it either by using an https URL for Server (like 'https://couchbase.server'), or by setting the UseSSL property to True.
Connecting to Couchbase Analytics Service
By default, the driver connects to the N1QL Query service. In order to connect to the Couchbase Analytics service, you will also need to set the CouchbaseService property to Analytics.
Connecting to Couchbase Cloud
A few special settings are required to connect to Couchbase Cloud:
- Set the ConnectionMode to Cloud
- Set the User and Password as described below in the Standard Authentication section. This is currently the only supported method of authenticating to Couchbase Cloud.
- Set the Server option to the domain listed in the Couchbase Cloud console.
- Enable the UseSSL option.
- Set the DNSServer option to a DNS server. In most cases this should be a public DNS service like 188.8.131.52 or 184.108.40.206.
- Set the SSLServerCert option to * to trust the Couchbase server certificate. You can also provide the certificate using that option or your trust store if you want the driver to validate it.
Authenticating with Standard Authentication
To authenticate with standard authentication, set the following:
- User: The user authenticating to Couchbase.
- Password: The password of the user authenticating to Couchbase.
Authenticating with Client Certificates
The driver supports authenticating with client certificates when SSL is enabled. To use client certificate authentication, set the following properties. Note that the User and Password options are not required when using client certificates.
- SSLClientCertType: Required. The type of client certificate set within SSLClientCert.
- SSLClientCert: Required. The client certificate in the format given by SSLClientCertType. Usually the path to your private key file.
- SSLClientCertPassword: Optional. The password of the client certificate if it is encrypted.
- SSLClientCertSubject: Optional. The subject of the client certificate, by default the first certificate found in the store. This is required if more than one certificate is available in the certificate store.
Authenticating Using a Credentials File
You can also authenticate using using a CredentialsFile. For more information on how to format your credentials file, refer to Couchbase's documentation. Note that the User and Password are not required when using a credentials file.