Database Reference
In-Depth Information
" current_change, cur-
rent_change_percent) VALUES " +
"(756716f7-2e54-4715-9f00-91dcbea6cf50,
'AMZN', " +
" 297.92, -0.94, -0.31);");
}
Reading Data
When reading data, the query execution will return an instance of
ResultSet
that will allow access to the values of the fields requested.
Listing 9.6
shows query
execution and printing the results to the console.
Listing 9.6
Reading Data in Java
public void printResults(){
ResultSet results = session.execute("SELECT *
FROM " +
"portfolio_demo.portfolio WHERE portfolio_id
= " +
"756716f7-2e54-4715-9f00-91dcbea6cf50;");
for (Row row : results) {
Sys-
tem.out.println(String.format("%-7s\t%-7s\t%-7s\t%-7s
\n%s",
"Ticker", "Price", "Change", "PCT",
"........+........+........+........"));
Sys-
tem.out.println(String.format("%-7s\t%0.2f\t%0.2f\t%0.2f",
row.getString("ticker"),
row.getDecimal("current_price"),
row.getDecimal("current_change"),
row.getFloat("current_change_percent") ));
}
}