相关文章推荐
近视的豆浆  ·  PostgreSQL - ...·  2 周前    · 
近视的剪刀  ·  PostgreSQL和Oracle的sql差 ...·  4 天前    · 
暴走的小熊猫  ·  postgresql pivot - CSDN文库·  3 小时前    · 
谦逊的佛珠  ·  深入分析Kafka ...·  1 年前    · 
温柔的仙人掌  ·  c# - JsonConvert ...·  1 年前    · 
活泼的双杠  ·  Ubuntu 11.10_百度百科·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Want to improve this question? Update the question so it focuses on one problem only by editing this post .

Closed 8 years ago .

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!

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);