Reputation: 3755
I am trying to use the datastax java driver and retrieve and return JSON.
ResultSet resultSet = session.execute("SELECT JSON * FROM event");
Row row = resultSet.one();
String json1 = row.getString(0);
String json2 = row.getString("[json]");
System.out.println(resultSet.toString());
returns ResultSet[ exhausted: false, Columns[[json](varchar)]]
At this point of time, I'm aware of the code to retrieve one row. I wish to return all rows as a json string
Upvotes: 0
Views: 980
Reputation: 8812
At this point of time, I'm aware of the code to retrieve one row. I wish to return all rows as a json string.
Java 8 StringJoiner: https://docs.oracle.com/javase/8/docs/api/java/util/StringJoiner.html
StringJoiner jsonString = new StringJoiner(",", "[", "]");
for(Row row: resultSet.all()) {
String json = row.getString(0);
jsonString.add(json);
}
return jsonString.toString();
Upvotes: 2