Java localhost/127.0.0.1:9042]无法连接

Java localhost/127.0.0.1:9042]无法连接,java,cassandra,connection,Java,Cassandra,Connection,试图通过下面的代码将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 requi

试图通过下面的代码将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。以下是完整的文档:

请发布正确的错误消息/回溯以及在环境中传递的变量值。由于您使用的是Windows计算机来运行Cassandra,请使用命令netstat-aon检查是否有任何进程正在默认Cassandra端口9042上侦听。如果某个进程正在侦听端口,请检查任务管理器的“详细信息”选项卡中的PID。没有特别侦听127.0.0.1:9042的应用程序。这意味着您的Cassandra本身没有运行。请分享您用来在windows计算机上安装Cassandra的指南。运行cqlsh时,我可能会遇到一些问题。我没有收到任何错误,但我没有被导航到cqlsh命令行。PFB C:\Users\spant2\Downloads\apache-cassandra-3.11.5\bin>cqlsh[127.0.0.1[9042]]C:\Users\spant2\Downloads\apache-cassandra-3.11.5\bin>