I'm trying to read data from a VoltDB database with Java. Now, it can be done using result sets from SQL statements, but there should (I'm told) be another way of doing it, native to VoltDB, similarly to how data is written to a VoltDB database (with client.callProcedure). I can't figure out how to do that; it seems like it should be a pretty simple thing to do, but I don't see any simple way to do it in client.
Java- read data from voltdb with native procedure
839 Views Asked by Lateral At
2
There are 2 best solutions below
0

If you want to use client.callProcedure function. You have to make that procedure in VoltDB's user interface . For example,
CREATE PROCEDURE insertNumber AS
INSERT INTO NUMBERS (number1) values (1)
this will create a procedure. When you call it with client.callProcedure(insertNumber), that will do the work.
Yes, if you are using client.callProcedure for your writes, you can certainly use the same API for your reads. Here is a simple example:
Here is a shortened example:
Rather than procname and parameters, you could also call AdHoc SQL like this:
These examples above are synchronous or blocking calls. If you want your application to use asynchronous calls, you can also use a Callback object with the call, so the client would continue executing subsequent code. When the response is received by the client thread that handles callbacks, the result could be passed off to another thread in our application to read the results.
You can read more about the API in the Java Client API Javadoc.