Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Data Base DUMP through Java

 
Mark Kafe
Ranch Hand
Posts: 60
Hibernate Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey
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
Marshal
Posts: 34837
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jason Cohen
Smart Bear Support
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic