可读字节不足-需要4,最大值为0

vmpqdwk3  于 2021-06-02  发布在  Hadoop
关注(0)|答案(3)|浏览(261)

当连接到cassandra数据库并创建一个键空间时,我得到了以下错误。
线程“main”>com.datastax.driver.core.exceptions.nohostavailableexception中出现异常:
所有尝试查询的主机都失败(尝试次数:/127.0.0.1:9042)
(com.datastax.driver.core.connectionexception:[/127.0.0.1:9042]传输初始化期间出现意外错误
(com.datastax.driver.core.transportexception:[/127.0.0.1:9042]触发意外异常(java.lang.indexoutofboundsexception:可读字节不足-需要4,最大值为0)))
这是我的密码:

package com.hadoop.reloaded.cassandra;

import com.datastax.driver.core.*;

public class CassandraOne {

    public static void main(String[] args){

        Cluster cluster1 = Cluster.builder().withPort(9042).addContactPoint("127.0.0.1").build();
        Session session = cluster1.connect();
        String query = "CREATE KEYSPACE test WITH replication "
                + "= {'class':'SimpleStrategy', 'replication_factor':1}; ";
        session.execute(query);
        session.execute("USE test");

    }
}

当我运行它时会抛出这个异常:

Exception in thread "main" com.datastax.driver.core.exceptions.NoHostAvailableException:
All host(s) tried for query failed (tried: /127.0.0.1:9042 (
    com.datastax.driver.core.ConnectionException: [/127.0.0.1:9042] 
        Unexpected error during transport initialization (
            com.datastax.driver.core.TransportException: [/127.0.0.1:9042]
                Unexpected exception triggered (java.lang.IndexOutOfBoundsException: Not enough readable bytes - Need 4, maximum is 0))))

    at com.datastax.driver.core.ControlConnection.reconnectInternal(ControlConnection.java:196)
    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.hadoop.reloaded.cassandra.CassandraOne.main(CassandraOne.java:13)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
ijxebb2r

ijxebb2r1#

在将驱动程序升级到 cassandra-driver-core-3.0.3.jar 和这张照片一样性感。问题已解决

kuhbmx9i

kuhbmx9i2#

可能是编码问题?
更多dé此链接的尾部

w8ntj3qf

w8ntj3qf3#

我猜您使用的datastax java驱动程序版本太旧了。检查是否运行3.0.0或更高版本,因为这是连接到cassandra 3.x群集所必需的。

相关问题