Cassandra 1.2.6从groovy访问

时间:2014-08-13 00:14:47

标签: groovy cassandra datastax

我使用以下代码访问cassandra。

import com.datastax.driver.core.Cluster
import com.datastax.driver.core.Host
import com.datastax.driver.core.Metadata
import com.datastax.driver.core.ResultSet
import com.datastax.driver.core.Session


class CassandraDB {

    private connect(String keyspace, String IP1) {

        Cluster cluster
        Session session

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

        Metadata metadata = cluster.getMetadata();
        System.out.printf("Connected to cluster: %s\n",
                metadata.getClusterName());
        for (Host host : metadata.getAllHosts()) {
            System.out.printf("Datacenter: %s; Host: %s; Rack: %s\n",
                    host.getDatacenter(), host.getAddress(), host.getRack());
        }

        session = cluster.connect(keyspace)
    }


 public static void main(String[] args) {
        CassandraDB conn = new CassandraDB()
        conn.connectCuster("dmb", "localhost" )

    }
}

问题是当我运行main方法时出现以下错误。 但是这个错误不会发生在cassandra version 2.0

错误:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.NullPointerException
    at com.datastax.driver.core.Metadata.buildTableMetadata(Metadata.java:123)
    at com.datastax.driver.core.Metadata.rebuildSchema(Metadata.java:88)
    at com.datastax.driver.core.ControlConnection.refreshSchema(ControlConnection.java:287)
    at com.datastax.driver.core.ControlConnection.tryConnect(ControlConnection.java:230)
    at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:170)
    at com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:78)
    at com.datastax.driver.core.Cluster$Manager.init(Cluster.java:970)
    at com.datastax.driver.core.Cluster$Manager.access$100(Cluster.java:885)
    at com.datastax.driver.core.Cluster.getMetadata(Cluster.java:229)
    at com.datastax.driver.core.Cluster$getMetadata.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
    at au.com.apdm.util.NewCassandra.connectCuster(NewCassandra.groovy:34)
    at au.com.apdm.util.NewCassandra.this$2$connectCuster(NewCassandra.groovy)
    at au.com.apdm.util.NewCassandra$this$2$connectCuster.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
    at au.com.apdm.util.NewCassandra.main(NewCassandra.groovy:47)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

看起来datastax库错误。有没有解决方案,而不是升级Cassandra。

Thax

1 个答案:

答案 0 :(得分:1)

猜测你可能会遇到以下错误:

https://datastax-oss.atlassian.net/browse/JAVA-280

如果是,请尝试更新到最新版本的驱动程序。