Scylla Documentation Logo Documentation
  • Server
    • Scylla Open Source
    • Scylla Enterprise
    • Scylla Alternator
  • Cloud
    • Scylla Cloud
    • Scylla Cloud Docs
  • Tools
    • Scylla Manager
    • Scylla Monitoring Stack
    • Scylla Operator
  • Drivers
    • CQL Drivers
    • DynamoDB Drivers
Download
Menu
Scylla Java Driver Manual Core driver Statements

Statements¶

Quick overview¶

What you pass to session.execute().

  • three types: simple (textual query), bound (prepared) and batch.

  • built-in implementations are immutable. Setters always return a new object, don’t ignore the result.


To execute a CQL query, you create a Statement instance and pass it to Session#execute or Session#executeAsync. The driver provides various implementations:

  • SimpleStatement: a simple implementation built directly from a character string. Typically used for queries that are executed only once or a few times.

  • BoundStatement (from PreparedStatement): obtained by binding values to a prepared query. Typically used for queries that are executed often, with different values.

  • BatchStatement: a statement that groups multiple statements to be executed as a batch.

All statement types share a common set of execution attributes, that can be set through either setters or a builder:

  • execution profile name, or the profile itself if it’s been built dynamically.

  • idempotent flag.

  • tracing flag.

  • query timestamp.

  • page size and paging state.

  • per-query keyspace (Cassandra 4 or above).

  • token-aware routing information (keyspace and key/token).

  • normal and serial consistency level.

  • query timeout.

  • custom payload to send arbitrary key/value pairs with the request (you should only need this if you have a custom query handler on the server).

When setting these attributes, keep in mind that statements are immutable, and every method returns a different instance:

SimpleStatement statement =
    SimpleStatement.newInstance("SELECT release_version FROM system.local");

// Won't work: statement isn't modified in place
statement.setConfigProfileName("oltp");
statement.setIdempotent(true);

// Instead, reassign the statement every time:
statement = statement.setConfigProfileName("oltp").setIdempotent(true);

All of these mutating methods are annotated with @CheckReturnValue. Some code analysis tools – such as ErrorProne – can check correct usage at build time, and report mistakes as compiler errors.

Note that some attributes can either be set programmatically, or inherit a default value defined in the configuration. Namely, these are: idempotent flag, query timeout, consistency levels and page size. We recommended the configuration approach whenever possible (you can create execution profiles to capture common combinations of those options).

PREVIOUS
SSL
NEXT
Batch statements
  • 4.13.0.x
    • 4.13.0.x
    • 4.12.0.x
    • 4.11.1.x
    • 4.10.0.x
    • 4.7.2.x
    • 3.11.2.x
    • 3.11.0.x
    • 3.10.2.x
    • 3.7.2.x
  • Java Driver for Scylla and Apache Cassandra®
  • API Documentation
  • Manual
    • API conventions
    • Case sensitivity
    • Core driver
      • Address resolution
      • Asynchronous programming
      • Authentication
      • Bill of Materials (BOM)
      • Compression
      • Configuration
        • Reference configuration
      • Control connection
      • Custom codecs
      • Detachable types
      • Using the driver in GraalVM native images
      • Query idempotence
      • Integration
      • Load balancing
      • Logging
      • Metadata
        • Node metadata
        • Schema metadata
        • Token metadata
      • Metrics
      • Native protocol
      • Non-blocking programming
      • Paging
      • Performance
      • Connection pooling
      • Query timestamps
      • Reactive Style Programming
      • Reconnection
      • Request tracker
      • Retries
      • Using the shaded JAR
      • Speculative query execution
      • SSL
      • Statements
        • Batch statements
        • Per-query keyspace
        • Prepared statements
        • Simple statements
      • Temporal types
      • Request throttling
      • Query tracing
      • Tuples
      • User-defined types
    • Developer docs
      • Administrative tasks
      • Common infrastructure
        • Concurrency
        • Driver context
        • Event bus
      • Native protocol layer
      • Netty pipeline
      • Request execution
    • Mapper
      • Integration
        • Kotlin
        • Lombok
        • Java 14 Records
        • Scala
      • DAOs
        • Custom result types
        • Delete methods
        • GetEntity methods
        • Increment methods
        • Insert methods
        • Null saving strategy
        • Query methods
        • Query provider methods
        • Select methods
        • SetEntity methods
        • Statement attributes
        • Update methods
      • Entities
      • Mapper interface
    • OSGi
    • Query builder
      • Conditions
      • DELETE
      • Idempotence in the query builder
      • INSERT
      • Relations
      • Schema builder
        • Aggregate
        • Function
        • Index
        • Keyspace
        • Materialized View
        • Table
        • Type
      • SELECT
      • Terms
      • TRUNCATE
      • UPDATE
  • Upgrade guide
  • Frequently asked questions
  • Changelog
  • Create an issue
  • Edit this page

On this page

  • Statements
    • Quick overview
Logo
Docs Contact Us About Us
Mail List Icon Slack Icon
© 2022, ScyllaDB. All rights reserved.
Last updated on 25 May 2022.
Powered by Sphinx 4.3.2 & ScyllaDB Theme 1.2.2