X

The Oracle NoSQL Database Blog covers all things Oracle NoSQL Database. On-Prem, Cloud and more.

Connect to Oracle Cloud simulator from IntelliJ in under five minutes

Vandanadevi Rajamani
Principal User Assistance Developer

Are you a NoSQL developer coding in Java? Do you use an IDE, such as IntelliJ, for developing your application code? Do you need help quickly connecting to an Oracle NoSQL database? Read on to learn more.

IntelliJ is one of the most popular Java IDEs. It comes with a rich set of features on its own, but you can make even more of it by using its plugins.

 

The Oracle NoSQL Database Cloud Simulator simulates the cloud service and lets you write and test applications locally without accessing Oracle NoSQL Database Cloud Service. The Oracle NoSQL Database Java SDK contains a few examples for the developer to get started with.

As a developer, you can get familiar with the Cloud APIs by using the Oracle NoSQL Database Cloud Simulator. You can start developing your application in the Oracle NoSQL Database Cloud Simulator, using and understanding the basic examples before starting with Oracle NoSQL Database Cloud Service.

The Oracle NoSQL Database Cloud Service IntelliJ plugin connects to a running instance of the Oracle NoSQL Database Cloud simulator and allows you to:

  • Quickly get started with Oracle NoSQL Database by using the examples available with the plugin.
  • View the tables in your Cloud simulator.
  • Retrieve columns, indexes, primary keys, and shard keys for each table.
  • Build and test your SQL queries on a table and obtain results in a tabular format.
  • View the data in each column in the JSON format.

The Oracle NoSQL Database Cloud Simulator is available for download from the Oracle Cloud website.

  • Download the Oracle NoSQL Database SDK file from the Oracle NoSQL SDK download page.
  • Gunzip and untar the .tar.gz package (or extract the files if you have downloaded a .zip package).

To use the Oracle NoSQL Database Cloud Simulator, you must download one of the supported Oracle NoSQL language SDKs. The SDKs have instructions and example code to connect to either the Oracle NoSQL Database Cloud Simulator or the Oracle NoSQL Database Cloud Service.

Once connected to the Oracle NoSQL Cloud Simulator, you can do the following.

Create a table add data to it:

final String createTableStatement =
  "CREATE TABLE IF NOT EXISTS " + tableName +
  "(cookie_id LONG, " +
  " audience_data JSON, " +
  " PRIMARY KEY(cookie_id))";
  TableRequest tableRequest = new TableRequest()
            .setStatement(createTableStatement)
            .setTableLimits(new TableLimits(50, 50, 50));
  TableResult tres = handle.tableRequest(tableRequest);

 

MapValue value = new MapValue()
            .put("cookie_id", 123) // fill in cookie_id
            .put("audience_data", // fill in audience_data
            "{\"ipaddr\" : \"10.0.00.xxx\"," +
            " \"audience_segment\": { " +
            " \"sports_lover\" : \"2018-11-30\"," +
            " \"book_reader\" : \"2018-12-01\"" +
            " }" +
            " }");
PutRequest putRequest = new PutRequest()
            .setValue(value)
            .setTableName(tableName);
PutResult putRes = handle.put(putRequest);

 

View data on the table

String query = "SELECT * from " + tableName + "
    WHERE cookie_id = 456";
List results = Common.runQuery(handle, query);
System.out.println("Number of query results for " +query +
     ": " + results.size());
for (MapValue qval : results) {
    System.out.println("\t" + qval.toString());
}

 

Drop the table from the database

tableRequest = new TableRequest()
      .setStatement("DROP TABLE IF EXISTS " + tableName);
tres = handle.tableRequest(tableRequest);

 

Watch this video to understand the simple steps to connect to an Oracle NoSQL database from IntelliJ Plugin using the Oracle NoSQL Database Cloud simulator.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.