繁体   English   中英

package com.datastax.driver.core 不存在

[英]package com.datastax.driver.core does not exist

I'm begginner in cassandra, I'm trying to connect to cassandra database and insert some rows in netbeans but I have error under the import: package com.datastax.driver.core does not exist any solutions?


import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;

public class CassandraConnection {
    public static void main(String args[])
    {
        System.out.println("Cassandra Java Connection");
        Cluster cluster;
        Session session;
        //Connect to the cluster and Keyspace ecommerce
        cluster=Cluster.builder().addContactPoint("localhost").build();
        session=cluster.connect("ecommerce");
        System.out.println("Inserting Data in Cassandra");
        session.execute("INSERT INTO products (pdt_id, cat_id, pdt_name, pdt_desc, price, shipping) VALUES (001,104, 'Danby 0.7 cu. ft. Microwave Oven', 'Capacity of 0.7 cu. ft.10 different power levels', 54.00, 'Expedited')");
        String pdtid = null, pdtname = null, pdtdesc = null;
        float price = 0;
        ResultSet resultset=session.execute("select * from products where pdt_id=005");
        for(Row row :resultset){
            pdtid = Integer.toString(row.getInt("pdt_id"));
            pdtname = row.getString("pdt_name");
            pdtdesc = row.getString("pdt_desc");
            price = row.getFloat("price");
            
            
        System.out.println("Product ID: " + pdtid);
        System.out.println("Name: " + pdtname);
        System.out.println("Description: " + pdtdesc);
        System.out.println("Price: "+ price);


        }
        cluster.close();
        }

}```

看起来您没有正确配置依赖项,因此找不到 Java 驱动程序 package。 正如 Andreas 还指出的那样,您似乎正在使用已在 Java 驱动程序 v4.x 中重构的旧代码。

由于您是 Cassandra 的新手,我建议您查看https://www.datastax.com/dev ,我们有免费的代码示例和使用 Katacoda 的交互式教程。

For example, learn CRUD operations on Cassandra with the Java driver in this hands-on tutorial which launches a Cassandra cluster + a dev environment where you can code -- all in a single browser window: https://www.datastax.com/开发/场景/datastax-java-driver-apache-cassandratm-quickstart 全部免费,无需登录。

You can also have a look at the code samples on Astra and learn how to develop apps using REST API, GraphQL API or Document API without any Cassandra knowledge. 干杯!

尝试将 maven 依赖项(或 jar 文件添加到您的项目中)

<!-- https://mvnrepository.com/artifact/com.datastax.cassandra/cassandra-driver-mapping -->
        <dependency>
            <groupId>com.datastax.cassandra</groupId>
            <artifactId>cassandra-driver-mapping</artifactId>
            <version>3.11.0</version>
        </dependency>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM