1
votes

I am new to cassandra and I want to connect to cassandra with java jdbc.I use the code below and get this error message...

try {
  Class.forName(driver).newInstance();
  con = DriverManager.getConnection(url, username, password);
  System.out.println(con);
} catch(Exception e){
  e.printStackTrace();
}

ERROR: Exception in thread "main" java.lang.NoSuchMethodError: org.apache.cassandra.thrift.Cassandra$Client.set_cql_version(Ljava/lang/String;)V at org.apache.cassandra.cql.jdbc.CassandraConnection.(CassandraConnection.java:138) at org.apache.cassandra.cql.jdbc.CassandraDriver.connect(CassandraDriver.java:92) at java.sql.DriverManager.getConnection(DriverManager.java:620) at java.sql.DriverManager.getConnection(DriverManager.java:200) at connect.Connect.main(Connect.java:24)

also I use these jars:

  • hector-core-1.1-2
  • libthrift-0.6.1.jar
  • cassandra-jdbc-1.2.1.jar
  • cassandra-all-0.7.0.jar

Can anyone help me please?

2
You'll need the cql jar as well. Can download it from the Apache site.Chandana
What looks to me reason behind this error is multiple Cassandra thrift jar versions in classpath. This is something "Cassandra$Client.set_cql_version" introduced in Cassandra 1.2 but not available in earlier versions.Ashish Panery

2 Answers

2
votes

You are probably facing the version mismatch issue as mentioned by Anse Danesh. For working with Cassandra from with in Java, I would recommend using the DataStax Cassandra java driver
https://github.com/datastax/java-driver

Its really easy to work with and is properly maintained by the DataStax community.

1
votes

Sounds like a version mismatch between the JDBC jar and the other Cassandra jars.