Search code examples
jooq

How to pretty print the query results after calling fetch()?


I use fetch() and i get a org.jooq.impl.ResultImpl instance.
How to print them in nice way? Without me specifying the fields names(get the header from result)

Something like this :

+---+---+
| f1| f2|
+---+---+
|foo|  1|
|bar|  2|
+---+---+

I want something with header on top (even if a field name is duplicated), and the row results bellow.

I tried some methods from ResultImpl but i haven't found it yet.
intoMap() is nice but it complains when duplicate fields. I also tried intoList() but this way i get only the values, without the field names.

I want both header and rows, like the show() method in Apache Spark.


Solution

  • The simplest way to get this formatting is to just call Result.toString(). It calls through to Result.format() with a few sensible defaults for debugging. If you want to be in control of the formatting options, just call Result.format() yourself.

    See also the manual section about formatting text.