I have a VoltDB database with a table. I want get the result of my VoltDB stored procedure. This is the code
import org.voltdb.*;
public class isola extends VoltProcedure {
public final SQLStmt getLeast = new SQLStmt(" SELECT codice FROM prova WHERE ID=1;" );
public VoltTable[] run() throws VoltAbortException {
voltQueueSQL(getLeast);
VoltTable[] queryresults = voltExecuteSQL();
String results= queryresults[0].toString();
System.out.println("String: \n " + results);
return voltExecuteSQL();
}
}
And this is the output
String:
header size: 14
status code: -128 column count: 1
(CODICE:INTEGER), rows -
2
The correct result of query is only 2.
Why do I get this result? I want to have only 2 as a result.
Thanks in advance
queryresults[0] is a VoltTable object. The toString() method is converting that entire object into a String (which does not include the data itself, only metadata). You need to iterate through the rows in the VoltTable (usually this is done using advanceRow()) and retrieve the codice column using either getLong(0) or getLong("CODICE").
Also, the final return voltExecuteSQL() is going to return an empty VoltTable[] because the queued SQL statement was already executed and nothing else has been queued.