Suppose I have an existing embedded Derby database and I want to reverse engineer the SQL commands that are necessary to create this database. There are a number of tools that do this by allowing the user to select a table and to get the creation script for the table. SQuirreL SQL, NetBeans, etc. permit this functionality. I am interested in understanding the approach taken to do this.
This problem is motivated by the challenge of programmatically (through JDBC) removing all data from a database (without destroying the structure of the database). In order to do this you generally need to remove the constraints on the database and then issue SQL truncate commands. See this post for and outline of the approach. However, removing the constraints changes the structure.
If I can (through SQL or JDBC methods) reverse engineer the creation script for any database, then when the database needs refreshed (cleared of all data), I could just capture the creation script, delete the database, and then re-create the database via the script. I want to do this for an arbitrary database. An approach using only JDBC that would work with any JDBC compliant database would be ideal.
Other related StackOverFlow Q/A include how to truncate all tables in MySQL The recommendations here seem to be MySQL specific, but do provide some insights. There doesn't seem to be a way to turn of referential constraints for derby.
Perhaps there is an already developed open source API for this. I am looking for some ideas before having to do it myself.