I want to backup and restore a postgresql database using pg_dump. The issue is : In command line when i execute this command :
pg_dump -h localhost -p 5432 -U postgres -F t -f test2.tar myDatabase
i get this prompet mesage to provide the database password:
Mot de passe :
So, it works
But, in the context of java: I can only do:
String cmd = "pg_dump -U postgres -h localhost -p 5342";
cmd += " -F t -f " + file.getCanonicalPath();
cmd += " myDatabase";
Process p = Runtime.getRuntime().exec(cmd);
int result= p.waitFor();
if (result == 0) {
System.out.println("Backup created successfully");
} else {
System.out.println("There is an error");
}
The above code is not working. So, what i can do to provide the database password at runtime ?