I am using Datastax Java driver 2.1.7 and trying to use Batch Statement in an Atomic way. But the below code is not getting compile. I am seeing error on "batch.add" line as:-
The method add(RegularStatement) in the type Batch is not applicable for the arguments (BoundStatement)
Below is the code:
public void insertMetadata(List<DataMeta> metaAddress) {
Batch batch = QueryBuilder.batch();
try {
for (DataMeta data : metaAddress) {
PreparedStatement statement = session.prepare("INSERT INTO holder_table (address, name, last_modified_date, id) VALUES (?, ?, ?, ?)");
batch.add(statement.bind(data.getAddress(), data.getName(), data.getLastModifiedDate(), 1));
}
batch.setConsistencyLevel(ConsistencyLevel.QUORUM);
session.execute(batch);
} catch (NoHostAvailableException e) {
// log exception
} catch (QueryExecutionException e) {
// log exception
} catch (QueryValidationException e) {
// log exception
}
}
What is wrong?