0

I wrote a little application in Java to display my Cassandra DB entries like this

String do = "Select * from cert;";`

    ResultSet results = session.execute(do);
    for (Row row : results) {
        System.out.format("%s %s\n", row.getString("name"), row.getBytesUnsafe("cer"));

        session.close();
        cluster.close();

How can I display the "cer" column like it is shown in the command prompt?

Create table cert (name varchar Primary key, cer blob);

INSERT INTO cert (name, cer) VALUES ('fred', bigintAsBlob(3));

name | cer
------+--------------------
 fred | 0x0000000000000003`

I don't know which string formatter I had to use, I only get

java.nio.HeapByteBuffer[pos=0 lim=8 cap=8]

with "%s" or

true

with "%b".

Cœur
  • 37,241
  • 25
  • 195
  • 267
Marvin Kallohn
  • 943
  • 3
  • 9
  • 12
  • Extract a `byte[]` from the `ByteBuffer` returned by `getBytesUnsafe`, then use the solutions in the linked duplicate to format it to a hex string. (You can append the `0x` to the beginning.) – Sotirios Delimanolis Jul 09 '16 at 17:33
  • The datastax java driver has a utility class com.datastax.driver.core.utils.Bytes. You can use Bytes.toHexString(ByteBuffer) to get the same output format (0x....) – Andy Tolbert Jul 09 '16 at 18:02

0 Answers0