Use a query result for another query


I tried out some simple queries in a Java Application using OrientDBs Java API, like
OResultSet rs = db.query("Select * From V Where name = 'Dave'"); while(rs.hasNext()) { OResult row =; System.out.println(row); };

this prints out a list of all found vertices on the console, however I would like to be able to e.g. save the @rid of the vertices in a string variable to reuse them for other queries instead of only printing them out.
Is there any possibility to to this?

Thank you

Hi @Enovyn

First of all, always remember to close the result sets at the end (ie. rs.close() or use a try-with-resources block) :wink:

About the specific question, the OResultSet class has a stream interface, so you can do the following: -> x.getIdentity().orElse(null)).collect(Collectors.toList());

or -> x.getIdentity().orElse(null)).map(x -> String.valueOf(x)).collect(Collectors.joining(", "));

I hope it helps



Hi Luigi,

thank you to answering again :slight_smile:
It works, but how can I access the single fields of the list then, like e.g. when I want to use the third @rid of the list?


Nevermind, I think I found a solution by using the toArray() function :smiley:

Thank you so much for your help