Java连接到Cassandra NoHostAvailableException

时间:2016-12-01 11:55:13

标签: java database cassandra

我的Java代码:

public static void main(String[] args) {
    Cluster cluster;
    Session session;

    cluster = Cluster.builder()
                .addContactPoint("127.0.0.1")
                .withPort(9042)
                .build();

    session = cluster.connect("Bundesliga");

    session.execute("INSERT INTO test(c1,c2,c3,c4,c5) VALUES(0,0,0,0,0)");
}

错误讯息:

  

线程中的异常" main"   com.datastax.driver.core.exceptions.NoHostAvailableException:全部   尝试查询失败的主机(尝试:/127.0.0.1:9042(null))at   com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:196)     在   com.datastax.driver.core.ControlConnection.connect(ControlConnection.java:80)     在com.datastax.driver.core.Cluster $ Manager.init(Cluster.java:1145)     在com.datastax.driver.core.Cluster.init(Cluster.java:149)at   com.datastax.driver.core.Cluster.connect(Cluster.java:225)at   com.datastax.driver.core.Cluster.connect(Cluster.java:258)at   cassandra.cassandra_main.main(cassandra_main.java:19)

我已查看cassandra.yaml

  

start_native_transport:true

     

native_transport_port:9042

1 个答案:

答案 0 :(得分:1)

我修好了。

问题是,cassandra-driver-core的版本与cassandra版本不兼容。