Cassandra: The Definitive Guide: Distributed Data at Web Scale by Jeff Carpenter & Eben Hewitt

Cassandra: The Definitive Guide: Distributed Data at Web Scale by Jeff Carpenter & Eben Hewitt

Author:Jeff Carpenter & Eben Hewitt [Carpenter, Jeff]
Language: eng
Format: azw3
Publisher: O'Reilly Media
Published: 2016-06-29T04:00:00+00:00


Simple statement

Thankfully, we needn’t make things so hard on ourselves. The Java driver provides the SimpleStatement class to help construct parameterized statements. As it turns out, the execute() operation we saw before is actually a convenience method for creating a SimpleStatement.

Let’s try building a query by asking our Session object to create a SimpleStatement. Here’s an example of a statement that will insert a row in our hotels table, which we can then execute:

SimpleStatement hotelInsert = session.newSimpleStatement( "INSERT INTO hotels (hotel_id, name, phone) VALUES (?, ?, ?)", "AZ123", "Super Hotel at WestWorld", "1-888-999-9999"); session.execute(hotelInsert);

The first parameter to the call is the basic syntax of our query, indicating the table and columns we are interested in. The question marks are used to indicate values that we’ll be providing in additional parameters. We use simple strings to hold the values of the hotel ID, name, and phone number.

If we’ve created our statement correctly, the insert will execute successfully (and silently). Now let’s create another statement to read back the row we just inserted:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.