2

我无法使用以下代码连接到 Cassandra 集群:

public static boolean tableCreate() {
        // Query
        String query = "CREATE KEYSPACE store WITH replication "
                + "= {'class':'SimpleStrategy', 'replication_factor':1};";

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

        // Creating Session object
        Session session = cluster.connect("tutorialspoint");

        // Executing the query
        session.execute(query);

        // using the KeySpaceq
        session.execute("USE store");
        System.out.println("Keyspace created with store name");

        return true;
    }

它给了我这个错误:

Exception in thread "main" com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: /127.0.0.1 (null))

我在上面的代码中有什么错误?

Cassandra 在我的本地 Windows 10 64 位上运行,我还禁用了防火墙。

4

1 回答 1

3

您可能需要检查并可能更新您正在使用的 datastax 驱动程序的版本。我遇到了完全相同的错误(即连接时出现相同的错误消息),升级驱动程序“datastax”版本后问题消失了,我可以连接到数据库。

类似问题:无法连接到本地主机上运行的 Cassandra 集群

于 2017-05-15T10:29:47.697 回答