我正在尝试将cassandra与JAVA连接起来。添加了以下库: Apache的卡桑德拉 - CQL-1.0.3.jar Apache的卡桑德拉 - 节俭3.6.0.jar libthrift-0.9.2.jar SLF4J-API 1.7.21.jar SLF4J-简单1.7.21.jar
这是我的代码:
import java.sql.Connection;
import java.sql.DriverManager;
public class Main {
public static void main(String[] args) {
Connection con = null;
try {
Class.forName("org.apache.cassandra.cql.jdbc.CassandraDriver");
DriverManager.registerDriver(new org.apache.cassandra.cql.jdbc.CassandraDriver());
// con = DriverManager.getConnection("jdbc:cassandra://localhost:9042/key_space");
con = DriverManager.getConnection("jdbc:cassandra:root/root@localhost:9042/key_space");
}
catch (Exception ex)
{
System.out.println("Error: " + ex.getMessage());
}
}
}
当我使用第一个连接字符串时,它给了我以下错误:
Error: String index out of range: -1
但是,对于第二个连接字符串。发生此错误:
org.apache.cassandra.cql.jdbc.DriverResolverException: Read a negative frame size (-2080374784)
这是堆栈跟踪:
stack trace: org.apache.cassandra.cql.jdbc.DriverResolverException: Read a negative frame size (-2080374784)!
at org.apache.cassandra.cql.jdbc.CassandraConnection.<init>(CassandraConnection.java:91)
at org.apache.cassandra.cql.jdbc.CassandraDriver.connect(CassandraDriver.java:86)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at com.company.Main.main(Main.java:16)
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:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
我哪里错了?请帮助我。