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:
- Download the latest Oracle NoSQL Database Java SDK from GitHub.
- Extract (unzip) the downloaded file in a local repository.
- Launch IntelliJ IDEA and open your NoSQL project.
- 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.
- From the extracted Oracle NoSQL Database Java SDK directory, navigate to
oracle-nosql-java-sdk > examplesfolder. CopyBasicTableExampleandCommonjava files to your NoSQL project directory.TheBasicExampleTableprogram creates a table calledaudienceData, adds two rows into this table, queries the inserted rows, deletes the inserted rows, and finally drops theaudienceDatatable. - Before running the application program, you must provide the necessary
arguments to connect:
- From the menu, select Run > Edit Configurations.
- Select Add New Configuration and then select Application.
- In the window that appears on the right, enter your main class in the Name field.
- Under Build and run, specify the Java JDK path and enter the main class.
- 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> -useKVProxyOn-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 -useKVProxySecure:
.http://<proxy_host>:443 -useKVProxy -user <user> -password <password> - 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 compileRun the program by supplying the program arguments:mvn exec:java -Dexec.mainClass=BasicTableExample -Dexec.args="http://<proxy_host>:<proxy_http_port>" - 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 0Note:
As theBasicExampleTabledeletes the inserted rows and drops theaudienceDatatable, 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.