简体   繁体   中英

How to get result of query in VoltDB

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM