当我运行这个程序时,我在输出屏幕中得到了这个。我不知道有什么问题我有什么问题。
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());
}
}
}
这是输出:java.nio.HeapByteBuffer [pos = 86 lim = 91 cap = 159]
答案 0 :(得分:1)
您可以尝试获取字节并将其转换为字符串:
String name_result = new String(resultSet.getBytes("name"), "UTF-8");
System.out.println(name_result);
答案 1 :(得分:0)
尝试在SQL字符串中使用单引号:
String qry = "select name FROM tempcql where key = 'detail'";
答案 2 :(得分:0)
您正在以二进制格式获取值。但是您将列类型指定为字符串。相反,您需要说明如下:
ObjectInputStream is = rs.getBinaryStream("name");
ByetBuffer bb = (ByteBuffer)is.readObject();