jasonliu0704 avatar image
jasonliu0704 asked Erick Ramirez answered

Is it possible to see the actual queries built with prepared and bound statements?

SO I am using the datastax java driver session to build CQL query using preparedStatement and boundedStatement and use session to execute it.

Is there is way to check the actual CQL query the builder build during unit test without run a embedded or cassandra node in the JVM?

I have check simulacron which works for simple statement but doesn't work for prepared statement as it doesn't maintain any internal state for the data and the schema of a table.


java driver
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered

Older version

Have a look at QueryLogger in Java driver 3.x which has the ability to log all executed statements:

Cluster cluster = ...
QueryLogger queryLogger = QueryLogger.builder()

The usual caveats apply such as watch out for large query strings.

For more info, see Logging in Java driver 3.0. See the examples in the API docs.

Note that I've referenced 3.0 based on the link you provided. If you're writing a new app, we recommend that you use the latest 4.x series instead.

Current releases

Java driver 4.x uses request logger to log all requests. Here is an example for enabling it via a configuration file:

datastax-java-driver.advanced.request-tracker {
  class = RequestLogger

  logs {
    success.enabled = true

    slow {
      threshold = 1 second
      enabled = true

    error.enabled = tr
    max-query-length = 500
    show-values = true
    max-value-length = 50
    max-values = 50
    show-stack-traces = true

For details, see Request Logger. Cheers!

10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.