Laxmikant
Laxmikant

Reputation: 1621

How to get query with values from com.datastax.driver.core.PreparedStatement?

I am using datastax cassandra driver. How to get query with values from com.datastax.driver.core.PreparedStatement ?

The toString() method does not give any meaningful thing. I want to print the exact query string in logs.

How can i achieve this ?

Upvotes: 0

Views: 1657

Answers (1)

mikea
mikea

Reputation: 6667

You can get the query string from a PreparedStatement with the getQueryString method but you can't get the bound variables because they will be on a BoundStatement not a PreparedStatement.

I'm not sure if this is the easiest way to get the variables but you could do:

for (int index = 0; index < preparedStatement.getVariables().size(); index++) {
    log(boundStatement.getObject(index).toString());
}

You would have to construct a single query string yourself because the driver keeps the query and the bound variables separate.

Upvotes: 1

Related Questions