A small utility to quickly dump your database query results as a formatted ascii table.
- Supports both classic
ResultSet
objects and JPATypedQuery
objects. - Offers functions to print to
System.out
, a designatedPrintStream
or return a formattedString
+----+-------+--------+--------+
| ID | PRICE | COLOR | NAME |
+----+-------+--------+--------+
| 1 | 1.5 | yellow | Banana |
+----+-------+--------+--------+
<dependency>
<groupId>dev.bodewig.db2ascii</groupId>
<artifactId>db2ascii</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
import dev.bodewig.db2ascii.Db2Ascii;
/* usage with classic java.sql.ResultSet (and java.io.PrintStream) */
Db2Ascii.printResultSet(resultSet) // prints to System.out
Db2Ascii.printResultSet(resultSet, printStream)
String formattedResult = Db2Ascii.resultSetToString(resultSet)
/* usage with JPA jakarta.persistence.TypedQuery<X> (and java.io.PrintStream) */
Db2Ascii.queryResultToString(typedQuery) // prints to System.out
Db2Ascii.queryResultToString(typedQuery, printStream)
String formattedResult = Db2Ascii.queryResultToString(typedQuery)
You can check out the unit tests for more complete examples.
It is licensed under GPL-3.0 but can be used without any limitation as long as it is not modified or distributed - so it should be safe to use as a Maven dependency with the scope test
(but this is no legal advise).
Run git config --add include.path ../.gitconfig
to include the template config in your project config.