Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 622 Vote(s) - 3.55 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using Datastax Java Driver to query a row as a JSON

#1
I am trying to use the datastax java driver and retrieve the row as a JSON.

I do the classic
`SELECT JSON * from myTable WHERE id=1` and this returns a Json formatted string on CQL.

e.g `{ "uuid" : "12324567-...." }`

This works.

Now when, I try to do the same use the Java driver, I use (in scala)

val resultSet = session.execute(queryString)

I pick up one row from this result set using: `"resultSet.one()"`.
This has the string I need, but how do I pick this up?

Experiment: `resultSet.one().getColumnDefinitions.toString`

Prints: `Columns[ [json] (varchar) ]`

Experiment: `resultSet.one().toString()`
<br>
Prints: `Row[{"uuid": "3ce19e07-2280-4b31-9475-992bda608e70"}]` <- String I need

How do I pick up a simple string that represents the JSON in my program, without trying to split the strings above ?
Reply

#2
As noted in the the [Cassandra documentation](

[To see links please register here]

):

> The results for `SELECT JSON` will only include a single column named `[json]`. This column will contain the same JSON-encoded map representation of a row that is used for `INSERT JSON`.

In order to access the JSON value of the returned row, you need to use one of the `getString` methods defined on the [`Row`](

[To see links please register here]

) class to get the value of this column either by index or by name:

Row row = resultSet.one();
String json1 = row.getString(0);
String json2 = row.getString("[json]");
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through