permaculture playing cards*
The moose likes JDBC 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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Data Base DUMP through Java" Watch "Data Base DUMP through Java" New topic
Author

Data Base DUMP through Java

Mark Kafe
Ranch Hand

Joined: Jun 23, 2008
Posts: 60

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

Joined: May 26, 2003
Posts: 30136
    
150

Mark,
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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jason Cohen
Smart Bear Support
Greenhorn

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
http://blog.asmartbear.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Data Base DUMP through Java
 
Similar Threads
Exporting Data (Excel to Oracle)
Core Dump Solaris
CSV+truncate leading zero solution
Get Data Base Using Dialog Box
tomcat core dump