cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thn <>
Subject Proper Use of PreparedStatements in DataStax driver
Date Tue, 08 Oct 2013 18:10:09 GMT

I'm trying to determine the proper way to use PreparedStatements using the
datastax CQL Java driver;

so the API is 
Session session = ...
PreparedStatement ps = session.prepare("INSERT INTO <table-name> (column,
...) VALUES (?, ...)")
BoundStatement bs = new BoundStatement(ps);

//bind variables


1.  My question is should I only instantiate the PreparedStatement once and
reuse *the same instance* every time I want to execute an INSERT? 
Is that necessary to get the performance benefits of using

2.  Or does session.prepare("INSERT INTO <table-name> (column, ...) VALUES
(?, ...)") return the "same logical" PreparedStatement each time (it need
not necessarily be the identical (as in ==) instance), and you still get the
same performance benefits?  Note: this is how you used

If the answer is #1, then that means PreparedStatements are effectively
singletons and need to be multi-thread-safe and the app is responsible for
dealing with lifecycle issues presuming that the original Session dies or

I've looked at the datastax API  datastax API
<>  , chatted on IRC, and
no answer.
This seems to me as a pretty fundamental question

View this message in context:
Sent from the mailing list archive at

View raw message