Take the 2-minute tour ×

What should be the connection string while using CQL jdbc driver?

Will I be able to find a proper/complete example for CQL using CQL JDBC driver in Java online?

share|improve this question

2 Answers 2

up vote 9 down vote accepted

You'll need the cql jar from the apache site.

Here's the basic test I used after entering data via CLI (using sample from wiki):

public class CqlJdbcTestBasic {
public static void main(String[] args) {
    Connection con = null;
    try {
        con = DriverManager.getConnection("jdbc:cassandra:root/root@localhost:9160/MyKeyspace");

        String query = "SELECT KEY, 'first', last FROM User WHERE age=42";

        Statement stmt = con.createStatement();
        ResultSet result = stmt.executeQuery(query);

        while (result.next()) {

    } catch (ClassNotFoundException e) {
    } catch (SQLException e) {
    } finally {
        if (con != null) {
            try {
            } catch (SQLException e) {
                // TODO Auto-generated catch block
            con = null;

The user/password (root/root) seems arbitrary, just be sure to specify the Keyspace (MyKeyspace)

Note, 'first' is quoted in the query string because it is an CQL keyword

share|improve this answer
Hi, libjack That's a great reference. Thank you –  Tamil Oct 8 '11 at 6:11
Hi,libjack Does this driver support Composite Keys? I'm getting IndexOutOfBound Exception @ result.next, It works for other standard key formats but. –  Tamil Oct 10 '11 at 8:53
Not sure, I mainly use the CQL from within Hector API; and I have not had any problems using Composite Keys there. –  libjack Oct 11 '11 at 15:05
In ur composite keys implementation using hector, Do u delimit the keys with ':' or hector takes care of implementing composite keys? Can I have an example for it? –  Tamil Oct 12 '11 at 10:22
Follow up. The jar is not available. We have to d/l the source and build using maven. Thanks for the answer anyway. –  Jus12 Apr 4 '12 at 6:33

You may also try using the cassandra-jdbc driver from http://code.google.com/a/apache-extras.org/p/cassandra-jdbc/.

Alternatively using the following maven dependency:

share|improve this answer

Your Answer


