com.datastax.driver.core.exceptions.InvalidQueryException using Datastax Java driver

本小妞迷上赌 提交于 2019-12-24 12:39:50

问题


I created my column family like this from the CLI-

create column family profile
    with key_validation_class = 'UTF8Type'
    and comparator = 'UTF8Type'
    and default_validation_class = 'UTF8Type'
    and column_metadata = [
      {column_name : account, validation_class : 'UTF8Type'}
      {column_name : advertising, validation_class : 'UTF8Type'}
      {column_name : behavior, validation_class : 'UTF8Type'}
      {column_name : info, validation_class : 'UTF8Type'}
      ];

Now I was trying to insert into this column family using the Datastax Java driver-

public void upsertAttributes(final String userId, final Map<String, String> attributes) {

String batchInsert = "INSERT INTO PROFILE(id, account, advertising, behavior, info) VALUES ( '12345', 'hello11', 'bye2234', 'bye1', 'bye2') "; 

        CassandraDatastaxConnection.getInstance().getSession().execute(batchInsert);

    }

I am always getting this exception-

com.datastax.driver.core.exceptions.InvalidQueryException: unconfigured columnfamily profile

And by this way, I am trying to create connection/session initialization to Cassandra using Datastax java driver-

private CassandraDatastaxConnection() {

    try{
    cluster = Cluster.builder().addContactPoint("localhost").build();
    session = cluster.connect("my_keyspace");           
    } catch (NoHostAvailableException e) {

            throw new RuntimeException(e);
    }
}

I am running Cassandra 1.2.3. And I am able to connect to Cassandra using the above code. The only problem I am facing is while inserting.

The thing that I wanted to know is whether I can insert into Column Family (that I have created from CLI mode) using Datastax Java driver or not? As soon as I am trying to insert into Column Family which I have created in CLI mode, I always get the above exception.

But If I try to insert into another table that I have created in CQLsh mode, I am able to insert into that.

Any help will be appreciated.


回答1:


My guess: your CLI columnfamilies are in a different keyspace.



来源:https://stackoverflow.com/questions/16136525/com-datastax-driver-core-exceptions-invalidqueryexception-using-datastax-java-dr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!