We did something like this at my company, so I can help.
In any case you will need to go through all the tables in your application. This can either be all the tables in the database (via
Connection.getMetaData().getTables()) or you might already have that list.
Then for each table you get the table's column meta-data (like name, type, is-null, etc.) which you also can get through Connection.getMetaData(). Then of course you "SELECT * FROM <tablename>" for each table.
Now the question is, what to do with that data?
If the goal is to create a dump file
that can be executed directly against the database, then you literally write out statements like "DROP TABLE foo IF EXISTS" and "CREATE TABLE foo ( a, b, c )" and "INSERT INTO foo COLUMNS (...) VALUES (...)". That's fine, but it will probably work with only one type of table. Make sure you properly escape SQL string constants!
In my case the goal was to capture that data in XML form so that (a) we could restore it using other code we wrote, but also (b) any other tool could easily get access to the data. So you might consider that path too.