Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.iba.edu;
- import com.cloudant.client.api.ClientBuilder;
- import com.cloudant.client.api.CloudantClient;
- import com.cloudant.client.api.Database;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.List;
- import java.util.Properties;
- public class Cloudant_test {
- public static void main(String[] args) {
- Properties prop = new Properties();
- InputStream input = null;
- try {
- String filename = "cloudant.properties";
- input = Cloudant_test.class.getClassLoader().getResourceAsStream(filename);
- if (input == null) {
- System.out.println("Sorry, unable to find " + filename);
- return;
- }
- prop.load(input);
- } catch (IOException ex) {
- ex.printStackTrace();
- } finally {
- if (input != null) {
- try {
- input.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- CloudantClient client = ClientBuilder.account(prop.getProperty("account"))
- .username(prop.getProperty("user"))
- .password(prop.getProperty("password"))
- .build();
- System.out.println("-----------------------------------------");
- System.out.println("Connected to Cloudant");
- System.out.println("Server Version: " + client.serverVersion());
- System.out.println("-----------------------------------------");
- List<String> databases = client.getAllDbs();
- System.out.println("-----------------------------------------");
- System.out.println("All my databases : ");
- for ( String db : databases ) {
- System.out.println(db);
- }
- System.out.println("-----------------------------------------");
- // client.deleteDB("db_to_delete");
- // client.createDB("example_db");
- Database db = client.database("employee_directory", false);
- // db.save(new ExampleDocument(true));
- // System.out.println("You have inserted the document");
- // System.out.println("-----------------------------------------");
- ExampleDocument doc = db.find(ExampleDocument.class,"example_id");
- System.out.println(doc);
- }
- }
- -------
- package com.iba.edu;
- public class ExampleDocument {
- private String _id = "example_id";
- private String _rev = null;
- private boolean isExample;
- public ExampleDocument(boolean isExample) {
- this.isExample = isExample;
- }
- public String toString() {
- return "{ id: " + _id + ",\nrev: " + _rev + ",\nisExample: " + isExample + "\n}";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement