Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8121309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:26:48+00:00 2026-06-06T05:26:48+00:00

I am trying to use Astyanax for Cassandra with Java. I tried the example

  • 0

I am trying to use Astyanax for Cassandra with Java. I tried the example at https://github.com/Netflix/astyanax/wiki/Getting-Started. I have the code which I have just copied from this link:

package def;

import com.netflix.astyanax.AstyanaxContext;
import com.netflix.astyanax.Keyspace;
import com.netflix.astyanax.MutationBatch;
import com.netflix.astyanax.connectionpool.NodeDiscoveryType;
import com.netflix.astyanax.connectionpool.OperationResult;
import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
import com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl;
import com.netflix.astyanax.connectionpool.impl.CountingConnectionPoolMonitor;
import com.netflix.astyanax.impl.AstyanaxConfigurationImpl;
import com.netflix.astyanax.model.Column;
import com.netflix.astyanax.model.ColumnFamily;
import com.netflix.astyanax.model.ColumnList;
import com.netflix.astyanax.serializers.StringSerializer;
import com.netflix.astyanax.thrift.ThriftFamilyFactory;

public class sample {

    public static void main(String[] args) throws Exception{
    AstyanaxContext<Keyspace> context = new AstyanaxContext.Builder()
    .forCluster("Test Cluster")
    .forKeyspace("KeyspaceName")
    .withAstyanaxConfiguration(new AstyanaxConfigurationImpl()      
        .setDiscoveryType(NodeDiscoveryType.NONE)
    )
    .withConnectionPoolConfiguration(new ConnectionPoolConfigurationImpl("MyConnectionPool")
        .setPort(9160)
        .setMaxConnsPerHost(10)
        .setSeeds("127.0.0.1:9160")
    )
    .withConnectionPoolMonitor(new CountingConnectionPoolMonitor())
    .buildKeyspace(ThriftFamilyFactory.getInstance());

    context.start();
    Keyspace keyspace = context.getEntity();

    ColumnFamily<String, String> CF_USER_INFO =
              new ColumnFamily<String, String>(
                "Standard1",              // Column Family Name
                StringSerializer.get(),   // Key Serializer
                StringSerializer.get());  // Column Serializer

    // Inserting data
    MutationBatch m = keyspace.prepareMutationBatch();

    m.withRow(CF_USER_INFO, "acct1234")
      .putColumn("firstname", "john", null)
      .putColumn("lastname", "smith", null)
      .putColumn("address", "555 Elm St", null)
      .putColumn("age", 30, null);

    m.withRow(CF_USER_INFO, "acct1234")
      .incrementCounterColumn("loginCount", 1);

    try {
      OperationResult<Void> result = m.execute();
    } catch (ConnectionException e) {
    }

    System.out.println("completed the task!!!");

    OperationResult<ColumnList<String>> result =
              keyspace.prepareQuery(CF_USER_INFO)
                .getKey("Key1")
                .execute();
            ColumnList<String> columns = result.getResult();

            // Lookup columns in response by name 
            int age        = columns.getColumnByName("age").getIntegerValue();
            long counter   = columns.getColumnByName("loginCount").getLongValue();
            String address = columns.getColumnByName("address").getStringValue();

            // Or, iterate through the columns
            for (Column<String> c : result.getResult()) {
              System.out.println(c.getName());
            }
    }

}

But when I run this I am getting an exception:

log4j:WARN No appenders could be found for logger (com.netflix.astyanax.connectionpool.impl.ConnectionPoolMBeanManager).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
completed the task!!!
Exception in thread "main" com.netflix.astyanax.connectionpool.exceptions.BadRequestException: BadRequestException: [host=127.0.0.1(127.0.0.1):9160, latency=0(0), attempts=1] InvalidRequestException(why:Keyspace KeyspaceName does not exist)
    at com.netflix.astyanax.thrift.ThriftConverter.ToConnectionPoolException(ThriftConverter.java:159)
    at com.netflix.astyanax.thrift.ThriftSyncConnectionFactoryImpl$1.execute(ThriftSyncConnectionFactoryImpl.java:119)
    at com.netflix.astyanax.connectionpool.impl.AbstractExecuteWithFailoverImpl.tryOperation(AbstractExecuteWithFailoverImpl.java:52)
    at com.netflix.astyanax.connectionpool.impl.AbstractHostPartitionConnectionPool.executeWithFailover(AbstractHostPartitionConnectionPool.java:229)
    at com.netflix.astyanax.thrift.ThriftColumnFamilyQueryImpl$1.execute(ThriftColumnFamilyQueryImpl.java:180)
    at def.sample.main(sample.java:68)
Caused by: InvalidRequestException(why:Keyspace KeyspaceName does not exist)
    at org.apache.cassandra.thrift.Cassandra$set_keyspace_result.read(Cassandra.java:4874)
    at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:78)
    at org.apache.cassandra.thrift.Cassandra$Client.recv_set_keyspace(Cassandra.java:489)
    at org.apache.cassandra.thrift.Cassandra$Client.set_keyspace(Cassandra.java:476)
    at com.netflix.astyanax.thrift.ThriftSyncConnectionFactoryImpl$1.execute(ThriftSyncConnectionFactoryImpl.java:109)
    ... 4 more

Can anyone tell me what’s wrong with this? There is no proper documentation also available for this. So, can you just help me out. And even give me some links where I can get more examples on it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T05:26:51+00:00Added an answer on June 6, 2026 at 5:26 am
    why:Keyspace KeyspaceName does not exist
    

    The error above is pretty self explanatory. The keyspace does not exists when the application connect to the localhost. So ensure that you create the keyspace and then re-run your application.


    From the comment, I think you want to look into this . Excerpt from the thread,

    The Keyspace serves as a client only and does not create the keyspace
    or column family on cassandra. You can use the AsytanaxContext.Builder
    to construct a Cluster interface through which you can actually create
    the keyspace and column families.

    This unit test in this link should provide you sufficient information on how to create keyspace in your cluster.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying use a Java annotation in a Groovy class but have trouble to
I am trying use Google Maps for my work; I have downloaded an example
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I am trying use a Java Uploader in a ROR app (for its ease
Hi I'm trying use a datepicker on a field I have. I'm trying to
trying to use regex to replace any white space with &nbsp;, inside of example
I have been trying use the edit_post_link() function to contain an image. All of
I'm trying use eco for client-side templating. I have multiple .eco templates that I'd
I have a regex that I'm trying use to validate against strings. Trying to
I have a 3rd party DLL that I am trying to use in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.