简体   繁体   中英

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]

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

尝试在SQL字符串中使用单引号:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM