Creating applications using Oracle NoSQL Java SDK from IntelliJ

Learn to create applications from IntelliJ plugin using the Oracle NoSQL Java SDK package.

After connecting to the Oracle NoSQL Database, you can create applications using Oracle NoSQL Java SDK.

In this topic, you will run a sample application available within the Oracle NoSQL Java SDK package to create a table in Oracle NoSQL Database.

Perform the following steps:

  1. Download the latest Oracle NoSQL Database Java SDK from GitHub.
  2. Extract (unzip) the downloaded file in a local repository.
  3. Launch IntelliJ IDEA and open your NoSQL project.
  4. If you are using the Maven build system, ensure that you have added the required dependencies in pom.xml. For details, see Oracle NoSQL Java SDK GitHub.
  5. From the extracted Oracle NoSQL Database Java SDK directory, navigate to oracle-nosql-java-sdk > examples folder. Copy BasicTableExample and Common java files to your NoSQL project directory.
    The BasicExampleTable program creates a table called audienceData, adds two rows into this table, queries the inserted rows, deletes the inserted rows, and finally drops the audienceData table.
  6. Before running the application program, you must provide the necessary arguments to connect:
    1. From the menu, select Run > Edit Configurations.
    2. Select Add New Configuration and then select Application.
    3. In the window that appears on the right, enter your main class in the Name field.
    4. Under Build and run, specify the Java JDK path and enter the main class.
    5. Enter the required program arguments. Select Apply and then select Okay.

    Table 1-2 Program Arguments

    Program Arguments More Information
    On-premises non-secure connection:
    http://<proxy_host>:<proxy_http_port> -useKVProxy
    On-premises secure connection:
    http://<proxy_host>:<proxy_http_secureport> -useKVProxy [-user <user>] [-password password]

    For example, if your Proxy URL is http://<proxy_host>:<proxy_http_port>, the program argument must be:

    Non-secure: http://<proxy_host>:8080 -useKVProxy

    Secure: http://<proxy_host>:443 -useKVProxy -user <user> -password <password>

    .
  7. To run this program, select Run or press Shift + 10.

    Note:

    If you want to run the program from a terminal, use the following sample commands:

    Compile the program using the maven build system using:
    mvn compile
    Run the program by supplying the program arguments:
    mvn exec:java -Dexec.mainClass=BasicTableExample -Dexec.args="http://<proxy_host>:<proxy_http_port>"
  8. View the output in the Run tool window at the bottom. Verify the logs to confirm that the code execution is successful. You can see the display messages that indicate table creation, rows insertion, and so on.
    Sample output:
    Creating table audienceData
    Created table audienceData
    Put row: {"cookie_id":123,"audience_data":{"audience_segment":{"sports_lover":"2018-11-30","book_reader":"2018-12-01"},"ipaddr":"10.0.00.xxx"}} result=non-null Version
    Got row: {"cookie_id":123,"audience_data":{"audience_segment":{"sports_lover":"2018-11-30","book_reader":"2018-12-01"},"ipaddr":"10.0.00.xxx"}}
    Inserted row via query, result:
        {"NumRowsInserted":1}
    Got row inserted by query: {"cookie_id":106,"audience_data":{"audience_segment":{"foodie":"2020-06-01","sports_lover":"2020-05-10"},"ipaddr":"10.0.00.xxx"}}
    Put row from json: {"cookie_id":456,"audience_data":{"ipaddr":"10.0.00.yyy","audience_segment":{"sports_lover":"2019-01-05","foodie":"2018-12-31"}}}
    Got row inserted as JSON: {"cookie_id":456,"audience_data":{"audience_segment":{"sports_lover":"2019-01-05","foodie":"2018-12-31"},"ipaddr":"10.0.00.yyy"}}
    Query results for SELECT * from audienceData WHERE cookie_id = 456: 
        {"cookie_id":456,"audience_data":{"audience_segment":{"foodie":"2018-12-31","sports_lover":"2019-01-05"},"ipaddr":"10.0.00.yyy"}}
    Deleted key {"cookie_id":456} result=true
    Dropping table audienceData
    
    Process finished with exit code 0

    Note:

    As the BasicExampleTable deletes the inserted rows and drops the audienceData table, you can't view this table in the Schema Explorer. If you want to see the table in the Schema Explorer, comment the code that deletes the inserted rows and drops the table, and rerun the program.