gpt4 book ai didi

java - 本地主机/127.0.0.1 :9042] Cannot connect

转载 作者:行者123 更新时间:2023-12-01 18:31:54 26 4
gpt4 key购买 nike

尝试通过以下代码将 Cassandra 与 Java 连接并获取 localhost/127.0.0.1:9042] 无法连接错误-

    public static void main(String[] args)
{
Cluster cluster;
Session session;
//cluster connects to the address of the node provided.One contact point is required.Good to have multiple
cluster=Cluster.builder().addContactPoint("localhost").build();

session=cluster.connect("ecommerce");
session.execute("INSERT INTO products (pdt_id, cat_id, pdt_name, pdt_desc, price, shipping) VALUES (002,105, 'Candy 0.9 cu. ft. Washing Machine', 'Capacity of 1 cu. ft.10 different power levels', 64.00, 'Expedited')");
session.execute("INSERT INTO products (pdt_id, cat_id, pdt_name, pdt_desc, price, shipping) VALUES (003,106, 'Prestige 0.9 cu.cm. Pressure Cooker', 'Capacity: 18 qt.', 70.00, 'Dispatched from warehouse')");

String pdtid = null, pdtname = null, pdtdesc = null;
float price = 0;
ResultSet resultSet=session.execute("select * from products");
for(Row row:resultSet)
{
pdtid = Integer.toString(row.getInt("pdt_id"));
pdtname = row.getString("pdt_name");
}
cluster.close();
}

}

最佳答案

java 代码语法对我来说看起来是正确的。

请确保您的计算机上正在运行 Cassandra,并且端口 9042 打开(检查防火墙)。您可以检查执行 cqlsh 并查看 Cassandra 是否响应。

我发现您使用的是过时版本的驱动程序。您应该考虑升级到 4.x。这是完整的文档:https://docs.datastax.com/en/developer/java-driver/4.4/manual/core/

关于java - 本地主机/127.0.0.1 :9042] Cannot connect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60149581/

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