-4

after a search on the internet with no result, I turn to you! I would like to create a java program, that if you click on a button, it makes a backup of a database in postgresql. I saw that i must use pg_dump but do not understand how to make it work. can someone please help me?

thank you!

2 Answers2

0

Use Runtime to execute the command that you use to execute the command that you would normally use to backup your database from the console interface.

Blip
  • 3,061
  • 5
  • 22
  • 50
0

if you want to use an OS command inside a Java program, make this (with vivek answer):

public class Backup{
    public static void main(String[] args) throws java.io.IOException, java.lang.InterruptedException {
        final String cmd = "pg_dump  --format=c --username \"postgres\" db_name > \"D:\\pgBackup\\db_name.backup\"";

        java.lang.Runtime rt = java.lang.Runtime.getRuntime();
        java.lang.Process p = rt.exec(cmd);
    }
}
Steph
  • 779
  • 1
  • 8
  • 18