-1

I'm trying to connect to Cassandra from Java code using JDBC connection. Here are the jars I'm using

enter image description here

Now this is the code which I found in the Stackoverflow to do this:

String serverIP = "localhost";
String keyspace = "mykeyspace";

Cluster cluster = Cluster.builder()
          .addContactPoints(serverIP)
          .build();

Session session = cluster.connect(keyspace);

String cqlStatement = "SELECT * FROM users";




for (Row row : session.execute(cqlStatement)) {
      System.out.println(row.toString());
    }

But unfortunately it's throwing following exception:

log4j:WARN No appenders could be found for logger (com.datastax.driver.core.Cluster).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.NoSuchMethodError: org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder.<init>(IIIIIZ)V
    at com.datastax.driver.core.Frame$Decoder.<init>(Frame.java:130)
    at com.datastax.driver.core.Connection$PipelineFactory.getPipeline(Connection.java:795)
    at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:212)
    at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:188)
    at com.datastax.driver.core.Connection.<init>(Connection.java:93)
    at com.datastax.driver.core.Connection$Factory.open(Connection.java:432)
    at com.datastax.driver.core.ControlConnection.tryConnect(ControlConnection.java:216)
    at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:171)
    at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:79)
    at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:1104)
    at com.datastax.driver.core.Cluster.init(Cluster.java:121)
    at com.datastax.driver.core.Cluster.connect(Cluster.java:198)
    at com.datastax.driver.core.Cluster.connect(Cluster.java:226)
    at com.mabsisa.resources.Demo.main(Demo.java:28)

I search in the internet for this exception scenario. But not much information I found. Please help me in solving this issue as I need to fix this issue as early as possible...

Community
  • 1
  • 1
Abhinab Kanrar
  • 1,532
  • 2
  • 20
  • 46

2 Answers2

0

I think the problem comes from the netty version you are using. You are using the version 2.3.0 of netty and in that version the class

org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder

does not have the constructor which the cassandra driver needs. In the maven repository the cassandra driver core has a depedency with the version 3.9.0.FINAL of netty:

http://mvnrepository.com/artifact/com.datastax.cassandra/cassandra-driver-core/2.0.2

So, try to update your version of netty.

ftrujillo
  • 1,172
  • 1
  • 16
  • 30
0

Make sure you don't have two version of netty lying in your final build . I had the same problem where i had two version of netty 3.2.2 and 3.9.0 , latest datastax driver needs 3.9.0 .

Sindhu
  • 2,422
  • 2
  • 19
  • 17