Domanda

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]

È stato utile?

Soluzione

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);

Altri suggerimenti

Try using single quotes in your SQL string:

String qry = "select name FROM tempcql where key = 'detail'";

You are getting the value in the binary format.But you specified column type as string.Instead you need to say as follows:

ObjectInputStream is = rs.getBinaryStream("name");
ByetBuffer bb = (ByteBuffer)is.readObject();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top