我将使用Java API连接Cassandra数据库

时间:2017-01-25 02:54:08

标签: java cassandra

package com.nokia.main;

import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;

/*
 cassandra.contactpoints=localhost,127.0.0.1
 cassandra.port=9042
 cassandra.keyspace=ranga*/
public class CassandraConnection {
    public static void main(String[] args) {
        String serverIp = "127.0.0.1";
        String keyspace = "ranga";
        CassandraConnection connection;

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

        Session session = cluster.connect(keyspace);

        String cqlStatement = "SELECT * FROM employee";
        for (Row row : session.execute(cqlStatement)) {
            System.out.println(row.toString());
        }

    }

}

因此在线程" main"中获得异常异常com.datastax.driver.core.exceptions.NoHostAvailableException:尝试查询的所有主机都失败了(尝试:/127.0.0.1:9042(com.datastax.driver.core.exceptions.InvalidQueryException:unconfigure

0 个答案:

没有答案