com.datastax.driver.core.exceptio-6ren">
gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 14:48:46 25 4
gpt4 key购买 nike

在连接到 Cassandra 数据库并创建 key 空间时,出现以下错误。

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))))

这是我的代码:

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)

最佳答案

我猜您使用的 Datastax Java 驱动程序版本太旧。检查您是否正在运行 3.0.0 或更高版本,因为这是连接到 Cassandra 3.X 集群所必需的。

关于java - 可读字节不足 - 需要 4 个,最大值为 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38173391/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com