Search code examples
javacassandracqljdbc-odbc

how to retrieve column value from result set


when i run this program i got this in the output screen.I don't know what is the problem is there any thing i am missing.

import org.apache.cassandra.cql.jdbc.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.*;
import javax.sql.*;
public class Operations 
{
        public static void main(String[] args){ 
        try
        {
            Class.forName("org.apache.cassandra.cql.jdbc.CassandraDriver");
            Connection con = DriverManager.getConnection("jdbc:cassandra://localhost:9160/temp");
           //String  name = "name";
            String qry = "select name FROM tempcql where key = detail";
            Statement smt = con.createStatement();
            ResultSet resultSet = smt.executeQuery(qry);
            while(resultSet.next())
            {
                System.out.println(resultSet.getString("name"));
            }

        }
        catch(Exception e)
        {
            System.out.println(" : "+e.getMessage());
        }
            }
}

here is the output of this : java.nio.HeapByteBuffer[pos=86 lim=91 cap=159]


Solution

  • You could try getting the bytes and converting that to a String:

    String name_result = new String(resultSet.getBytes("name"), "UTF-8");
    System.out.println(name_result);