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

  • Home
  • SEARCH
  • 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 6347745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:16:50+00:00 2026-05-24T21:16:50+00:00

I new to Apache-Cassandra 0.8.2. I am trying to insert some data but getting

  • 0

I new to Apache-Cassandra 0.8.2. I am trying to insert some data but getting this exception.

Exception in thread "main" UnavailableException()
    at org.apache.cassandra.thrift.Cassandra$insert_result.read(Cassandra.java:14902)
    at org.apache.cassandra.thrift.Cassandra$Client.recv_insert(Cassandra.java:858)
    at org.apache.cassandra.thrift.Cassandra$Client.insert(Cassandra.java:830)
    at TestCassandra.main(TestCassandra.java:166)

My Code is:


public class TestCassandra {

    public static void createKeySpace( Cassandra.Client client,String ksname)
        throws TException, InvalidRequestException, UnavailableException, UnsupportedEncodingException, NotFoundException, TimedOutException, SchemaDisagreementException {

        KsDef ksdef = new KsDef();
        ksdef.name = ksname;
        ksdef.strategy_class = "NetworkTopologyStrategy";    
        List l = new ArrayList();        
        ksdef.cf_defs =l;   

        client.system_add_keyspace(ksdef); 
        System.out.println("KeySpace Created");


    }

    public static void createColumnFamily(Cassandra.Client client,String ksname,String cfname)
        throws TException, InvalidRequestException, UnavailableException, UnsupportedEncodingException, NotFoundException, TimedOutException, SchemaDisagreementException {

        CfDef cfd = new CfDef(ksname, cfname);
        client.system_add_column_family(cfd);
        System.out.println("ColumnFamily Created");

    }

    public static void main(String[] args)
            throws TException, InvalidRequestException, UnavailableException, UnsupportedEncodingException, NotFoundException, TimedOutException, SchemaDisagreementException {

        TTransport tr = new TFramedTransport(new TSocket("localhost", 9160));
        TProtocol proto = new TBinaryProtocol(tr);
        Cassandra.Client client = new Cassandra.Client(proto);
        tr.open();

       String keySpace = "Keyspace1";
       String columnFamily = "Users";

       //Drop the Keyspace 

       client.system_drop_keyspace(keySpace);

       //Creating keyspace


       KsDef ksdef = new KsDef();
       ksdef.name = keySpace;
       ksdef.strategy_class = "NetworkTopologyStrategy";    
       List l = new ArrayList();        
       ksdef.cf_defs =l;

       client.system_add_keyspace(ksdef); 
       System.out.println("KeySpace Created");

       //createKeySpace(client,keySpace);

       client.set_keyspace(keySpace);

       //Creating column Family

       CfDef cfd = new CfDef(keySpace, columnFamily);
       client.system_add_column_family(cfd);
       System.out.println("ColumnFamily Created");

       //createColumnFamily(client,keySpace,columnFamily);

       ColumnParent parent = new ColumnParent(columnFamily);

       Column description = new Column();
       description.setName("description".getBytes());
       description.setValue("I’m a nice guy".getBytes());
       description.setTimestamp(System.currentTimeMillis());

       ConsistencyLevel consistencyLevel = ConsistencyLevel.ONE;
       ByteBuffer rowid = ByteBuffer.wrap("0".getBytes());

//Line No. 166
       client.insert(rowid, parent, description, consistencyLevel);
       System.out.println("Record Inserted...");

       tr.flush();       
       tr.close();
    }


}

Can anybody help me why this is so?

  • 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-05-24T21:16:51+00:00Added an answer on May 24, 2026 at 9:16 pm

    The reason for the UnavailableException is due to the fact of in your createKeySpace method, you have never specified a replication_factor for your keyspace definition, KsDef.

    The 2 Strategy class, NetworkTopologyStrategy and SimpleStrategy requires a replication factor to be set. In Cassandra 0.8 and higher, there is no more a replication_factor field in KsDef so you will have to add it yourself, like so (I’ve updated your code, but not tested. Also, see that I’ve changed your strategy_class to SimpleStrategy):

    KsDef ksdef = new KsDef();
    ksdef.name = ksname;
    ksdef.strategy_class = SimpleStrategy.class.getName(); 
    
    //Set replication factor
    if (ksdef.strategy_options == null) {
        ksdef.strategy_options = new LinkedHashMap<String, String>();
    }
    
    //Set replication factor, the value MUST be an integer
    ksdef.strategy_options.put("replication_factor", "1");
    
    //Cassandra must now create the Keyspace based on our KsDef
    client.system_add_keyspace(ksdef);
    

    For NetworkTopologyStrategy, you will need to specify your replication factor to each datacentre you’ve created (See explanation here).

    For more information, view my Interfacing with Apache Cassandra 0.8 in Java blog.

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

Sidebar

Related Questions

I'm getting a NoClassDefFoundError exception on org.apache.commons.logging.LogFactory after I have already created an instance.
I just started using the new POI 3.6 http://poi.apache.org XSSF which was released in
new Date(05-MAY-09 03.55.50) is any thing wrong with this ? i am getting illegalArgumentException
I'm fairly new to Apache Cassandra and nosql in general. In SQL I can
I am very new to apache and django, so execuse me if this question
I'm new to apache-camel and I'm just trying to get a feel for what
I'm considering the use of Apache solr for indexing data in a new project.
I am new to Apache Xindice. I tried some examples from the internet and
I am relitively new to Apache Ivy and am trying to move an existing
I am new to Apache Camel. I am trying to build a pubsub pattern

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.