Creating applications using Oracle NoSQL Java SDK from Visual Studio Code
Learn to create applications from Visual Studio Code extension using the Oracle NoSQL Java SDK package.
After connecting to Oracle NoSQL Database, you can create and run applications using Oracle NoSQL Java SDK.
Perform the following steps:
Set up the Maven Project
Create and run a sample application program
-
Create a sample application code as follows. Update your connection's end point and port in the <proxy_host> and <proxy_https_port> placeholders.
package org.oracle.nosqljavasdk; import oracle.nosql.driver.NoSQLHandle; import oracle.nosql.driver.NoSQLHandleConfig; import oracle.nosql.driver.NoSQLHandleFactory; import oracle.nosql.driver.kv.StoreAccessTokenProvider; import oracle.nosql.driver.ops.GetRequest; import oracle.nosql.driver.ops.GetResult; import oracle.nosql.driver.ops.PutRequest; import oracle.nosql.driver.ops.PutResult; import oracle.nosql.driver.ops.TableRequest; import oracle.nosql.driver.ops.TableResult; import oracle.nosql.driver.values.MapValue; public class JavaVSCode { /* Name of your table */ final static String tableName = "TestSDK"; static NoSQLHandle handle; public static void main(String[] args) throws Exception { String kvstore_endpoint ="http:<proxy_host>:<proxy_http_port>"; handle = generateNoSQLHandle(kvstore_endpoint); try { createTable(handle); writeRows(handle); readRows(handle); /* Uncomment this if you want to drop the table */ //dropTable(handle); } catch (Exception e) { System.err.print(e); } finally { handle.close(); } } /* Create a NoSQL handle to access the onPremise Oracle NoSQL database */ private static NoSQLHandle generateNoSQLHandle(String kvstore_endpoint) throws Exception { NoSQLHandleConfig config = new NoSQLHandleConfig(kvstore_endpoint); config.setAuthorizationProvider(new StoreAccessTokenProvider()); /* If using a secure store, uncomment the line below and pass username, * password of the store to StoreAccessTokenProvider */ /* config.setAuthorizationProvider(new StoreAccessTokenProvider(username, password)); */ NoSQLHandle handle = NoSQLHandleFactory.createNoSQLHandle(config); return handle; } /** * Create a simple table with an integer key * and a single string data field * and set your desired table capacity */ private static void createTable(NoSQLHandle handle) throws Exception { String createTableDDL = "CREATE TABLE IF NOT EXISTS " + tableName + "(employeeid INTEGER, name STRING, " + "PRIMARY KEY(employeeid))"; TableRequest treq = new TableRequest() .setStatement(createTableDDL); System.out.println("Creating table " + tableName); TableResult tres = handle.tableRequest(treq); /* The request is async, * so wait for the table to become active. */ System.out.println("Waiting for " + tableName + " to become active"); tres.waitForCompletion(handle, 60000, /* wait 60 sec */ 1000); /* delay ms for poll */ System.out.println("Table " + tableName + " is active"); } /** * Construct a row and add it to the table */ private static void writeRows(NoSQLHandle handle) throws Exception { MapValue value = new MapValue().put("employeeid", 1).put("name", "Tracy"); PutRequest putRequest = new PutRequest().setValue(value).setTableName(tableName); PutResult putResult = handle.put(putRequest); if (putResult.getVersion() != null) { System.out.println("Wrote " + value); } else { System.out.println("Put failed"); } } /** * Set a key and read the row from the table */ private static void readRows(NoSQLHandle handle) throws Exception { MapValue key = new MapValue().put("employeeid", 1); GetRequest getRequest = new GetRequest().setKey(key).setTableName(tableName); GetResult getRes = handle.get(getRequest); System.out.println("Read " + getRes.getValue()); } /** * Drop the table and wait for the table to move to dropped state */ private static void dropTable(NoSQLHandle handle) throws Exception { System.out.println("Dropping table " + tableName); TableRequest treq = new TableRequest() .setStatement("DROP TABLE IF EXISTS " + tableName); TableResult tres = handle.tableRequest(treq); System.out.println("Waiting for " + tableName + " to be dropped"); tres.waitForCompletion(handle, 60000, /* wait 60 sec */ 1000); /* delay ms for poll */ System.out.println("Table " + tableName + " has been dropped"); } } - Run the Java program. You can press F5 or select the desired
option from the Run menu.
Note:
If you have network proxies, include them in the settings.xml file located in the maven directory. - You can view the output in the Visual Studio Code terminal.
The application code above creates the table
TestSDK, adds a row to the table, and reads the row from the
table.
Sample
output:
----------------< com.oracle.nosql.example:NoSQLOperation >-----------------
Building NoSQLOperation 1.0-SNAPSHOT
from pom.xml
--------------------------------[ jar ]---------------------------------
--- resources:3.3.1:resources (default-resources) @ NoSQLOperation ---
Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
skip non existing resourceDirectory C:\Users\ramya\javaVSCode\src\main\resources
--- compiler:3.8.0:compile (default-compile) @ HelloWorld ---
Changes detected - recompiling the module!
File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
Compiling 1 source file to C:\Users\ramya\javaVSCode\target\classes
--- exec:3.1.0:exec (default-cli) @ NoSQLOperation ---
Creating table TestSDK
Waiting for TestSDK to become active
Table TestSDK is active
Wrote {"name":"Tracy","employeeid":1}
Read {"employeeid":1,"name":"Tracy"}
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 8.013 s
Finished at: 2025-11-24T17:01:24+05:30
------------------------------------------------------------------------
You can also view the table from your Visual Studio Code Table Explorer. For details, see Managing Tables Using Visual Studio Code Extension.