# Java Hello World insert- fdbcli get Hello is not returning value

**URL:** <https://forums.foundationdb.org/t/java-hello-world-insert-fdbcli-get-hello-is-not-returning-value/291>\
**Category:** Using FoundationDB\
**Created:** [April 27, 2018, 3:29pm UTC](https://forums.foundationdb.org/t/java-hello-world-insert-fdbcli-get-hello-is-not-returning-value/291 "2018-04-27T15:29:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nchiring](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/nchiring/32/154_2.png) [@nchiring](https://forums.foundationdb.org/u/nchiring)\
**Post date:** [April 27, 2018, 3:29pm UTC](https://forums.foundationdb.org/t/java-hello-world-insert-fdbcli-get-hello-is-not-returning-value/291/1 "2018-04-27T15:29:50Z")

</div>

I am trying out the following basic example-

public static void main(String[] args) {  
// Run an operation on the database  
db.run((Transaction tr) -\> {  
tr.set(Tuple.from(“hello”).pack(), Tuple.from(“world”).pack());  
return null;  
});  
// Get the value of ‘hello’ from the database  
String hello = db.run((Transaction tr) -\> {  
byte[] result = tr.get(Tuple.from(“hello”).pack()).join();  
return Tuple.fromBytes(result).getString(0);  
});  
System.out.println("Hello " + hello);  
}

This prints “Hello World” correctly.  
However,  
fdbcli doesn’t find the key.

fdb\> get Hello  
`Hello’: not found

What am I missing here?

---

<div class="post-metadata">

**Author:** ![alloc](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/alloc/32/9_2.png) [@alloc](https://forums.foundationdb.org/u/alloc)\
**Post date:** [April 27, 2018, 3:51pm UTC](https://forums.foundationdb.org/t/java-hello-world-insert-fdbcli-get-hello-is-not-returning-value/291/2 "2018-04-27T15:51:37Z")

</div>

Ah. So, it appears that the code tuple packs the keys (and values). This a totally reasonable thing to do (as it massages the data so that they sort correctly), but it does change the byte representation, so you won’t be able to run `get Hello` from the CLI. As it turns out, the correct byte encoding for “Hello” is `\x02Hello\x00`, so I would expect that you would see:

```auto
fdb> get \x02Hello\x00
`\x02Hello\x00' is `\x02world\x00'

```

We have more details as to how exactly tuple encoding works [in the design directory](https://github.com/apple/foundationdb/blob/master/design/tuple.md). For strings, though, it is just (1) encode as UTF-8, (2) add a `\x02` byte at the beginning, (3) a `\x00` byte at the end, and (4) convert any zero bytes in the interior to `\x00\xff`.

---

<div class="post-metadata">

**Author:** ![nchiring](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/nchiring/32/154_2.png) [@nchiring](https://forums.foundationdb.org/u/nchiring)\
**Post date:** [April 27, 2018, 3:55pm UTC](https://forums.foundationdb.org/t/java-hello-world-insert-fdbcli-get-hello-is-not-returning-value/291/3 "2018-04-27T15:55:08Z")

</div>

Thank you @alloc. I suspected something to do with encoding, but couldn’t locate any related doc. Thanks for doc reference too.

---

<div class="post-metadata">

**Author:** ![ral](https://avatars.discourse-cdn.com/v4/letter/r/f04885/32.png) [@ral](https://forums.foundationdb.org/u/ral)\
**Post date:** [April 29, 2018, 4:02pm UTC](https://forums.foundationdb.org/t/java-hello-world-insert-fdbcli-get-hello-is-not-returning-value/291/4 "2018-04-29T16:02:34Z")

</div>

In general when I want to see what data I’ve inserted during tests I run

```
getrange \x00 \xff

```

to see every (non-system) key. Obviously this is only useful for very small databases but often helps in dev if you’re not sure how everything is serialized.

---

<div class="post-metadata">

**Author:** ![ajbeamon](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/ajbeamon/32/13_2.png) [@ajbeamon](https://forums.foundationdb.org/u/ajbeamon)\
**Post date:** [April 29, 2018, 5:50pm UTC](https://forums.foundationdb.org/t/java-hello-world-insert-fdbcli-get-hello-is-not-returning-value/291/5 "2018-04-29T17:50:50Z")

</div>

Technically, to read everything you’d want to also include the empty key, which is a legal key in FoundationDB. In fdbcli, you would do the following:

`getrange "" \xff`

It should be noted that in fdbcli, you _must_ use double quotes rather than single quotes for this (i.e. " instead of '). Single quotes are not treated as a special character, so using them will actually exclude everything that falls lexicographically before the single quote. For that reason, some intentionally use `\x00` as the starting key if they know the empty key is unset to avoid hitting that pitfall.
