jQuery in Action, 3rd edition
The moose likes JDBC and Relational Databases and the fly likes Data Base DUMP through Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Data Base DUMP through Java" Watch "Data Base DUMP through Java" New topic

Data Base DUMP through Java

Mark Kafe
Ranch Hand

Joined: Jun 23, 2008
Posts: 60

I want to create Dump file of data base in desktop application using Java. any one can help me about this....................
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33098

Do you know how to create a dump file using your database command line? If so, you could call that using Runtime.exec. If the database is on a separate machine than the desktop app, you'd also need to transfer the file.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Jason Cohen
Smart Bear Support

Joined: Jul 08, 2009
Posts: 6
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.

Jason Cohen
Founder, Smart Bear Software
I agree. Here's the link: http://aspose.com/file-tools
subject: Data Base DUMP through Java
It's not a secret anymore!