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 7542473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:10:33+00:00 2026-05-30T08:10:33+00:00

Im inserting data with hector and getting it back with JDBC. The data makes

  • 0

Im inserting data with hector and getting it back with JDBC.

The data makes no sence apart from the indexed column, im aware that this is because cassandra stores data as bytes and then converts it when its read (client converts it)

Does anyone know how to do this in JDBC for cassandra ?.

My code:

public static void main(String[] args) throws SQLException
    {
        Connection con = null;
        String _KS = "StringMsg";
        String _CFDef = "Tweets";

        try 
        {
            Class.forName("org.apache.cassandra.cql.jdbc.CassandraDriver");
            con = DriverManager.getConnection("jdbc:cassandra://localhost:9160/" + _KS);

            String query = "SELECT username, email, msg, id FROM " + _CFDef + " WHERE 'username'='LTodorov'";

            Statement stmt = con.createStatement();
            ResultSet result = stmt.executeQuery(query);

            System.out.println("hi");
            int i=0;
            while (result.next())
            {
                System.out.println(result.getString("id"));
                System.out.println(result.getString("username"));
                System.out.println(result.getString("msg"));
                System.out.println(result.getString("email"));
                System.out.print("count:" + i + "\n\n");i++;
            }
        } 
        catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        catch (SQLException e) {
            e.printStackTrace();
        }
        finally 
        {
            if (con != null) 
            {
                try 
                {
                    con.close();
                } 
                catch (SQLException e) 
                {
                    e.printStackTrace();
                }
                con = null;
            }
        }
    }

Results:

hi
java.nio.HeapByteBuffer[pos=237 lim=258 cap=798]
LTodorov
java.nio.HeapByteBuffer[pos=184 lim=209 cap=798]
java.nio.HeapByteBuffer[pos=144 lim=155 cap=798]
count:0

Cli Result:

GET Tweets Where username=LTodorov;
-------------------
RowKey: LTodorov1330045080096
=> (column=email, value=6c5f6c74404162762e6267, timestamp=1330045080214000)
=> (column=id, value=4c546f646f726f7631333330303435303830303936, timestamp=13300
45080098000)
=> (column=msg, value=54686973206973206d616b696e67206d652073616466616365, timest
amp=1330045080210000)
=> (column=username, value=LTodorov, timestamp=1330045080217000)

Cli Result with “assume Tweets validator as utf8”;

RowKey: LTodorov1330045080096
=> (column=email, value=l_ld@Abv.bg, timestamp=1330045080214000)
=> (column=id, value=LTodorov1330045080096, timestamp=1330045080098000)
=> (column=msg, value=This is making me sadface, timestamp=1330045080210000)
=> (column=username, value=LTodorov, timestamp=1330045080217000)

Column Family Definition:

CREATE COLUMN FAMILY Tweets
WITH comparator = UTF8Type
AND key_validation_class=UTF8Type
AND column_metadata = [
{column_name: id, validation_class: UTF8Type}
{column_name: email, validation_class: UTF8Type}
{column_name: msg, validation_class: UTF8Type}
{column_name: user, validation_class: UTF8Type}

Any cassandra gurus got any pointers? I’m getting the data back but should it be converted inside java, or should the JDBC api do the work or is it a cassandra thing ? (i think this cant be solved by cassandra)

  • 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-30T08:10:35+00:00Added an answer on May 30, 2026 at 8:10 am

    I think you should be able to do it in your java class. The result set return a few data types, look into method getBytes(). You can reconstructed the byte value to String. For example

    String string_username = new String(result.getBytes("username"), "UTF-8");
    System.out.println(string_username);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting strange error while inserting data into mysql table column. Details: Create
I think I got a good handle on UITableViews and on getting/inserting data from/to
I'm having trouble inserting data from my registration webform into sqlserver-2008. I'm getting an
i am inserting data that looks like this: AA00000111 PSNH-OT J, SMITH 03/01/2011 10/11/1957
i made this code for inserting data to an system mail that know to
The problem is during inserting data from staging table during import routine. The system
I get the following error when inserting data from mysql into postgres. Do I
I heard a rumor that when inserting binary data (files and such) into MySQL,
I'm writing a routine that validates data before inserting it into a database, and
Inserting rows one by one from a 600 record data-set is taking almost an

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.