我试图使用Java在posgresql中备份我的数据库,但是当我运行我的程序时,我得到了以下错误:
线程"main“java.io.IOException:无法运行程序"pg_dump":CreateProcess error=2中的异常,未找到指定的文件
这是我的密码
String path = "C:\\Program Files (x86)\\PostgreSQL\\9.1\\bin\\pg_dump.exe";
Runtime r = Runtime.getRuntime();
//PostgreSQL variables
String host = "localhost";
String user = "postgres";
String dbase = "GestionPharmacie";
String password = "*****";
Process p;
ProcessBuilder pb;
r = Runtime.getRuntime();
pb = new ProcessBuilder("pg_dump", "-v", "-h", host, "-f", path, "-U", user, dbase);
pb.environment().put("PGPASSWORD", password);
pb.redirectErrorStream(true);
p = pb.start();
发布于 2015-11-26 14:53:38
-D是一个无效的选项,我放置了一个主机属性。
{
String path = "D:\\aaa";
Runtime r = Runtime.getRuntime();
//PostgreSQL variables
String host = "localhost";
String user = "postgres";
String dbase = "GestionPharmacie";
String password = "*****";
Process p;
ProcessBuilder pb;
r = Runtime.getRuntime();
pb = new ProcessBuilder("pg_dump", "-v", "-h", host, "-f", path, "-U", user, dbase);
pb.environment().put("PGPASSWORD", password);
pb.redirectErrorStream(true);
p = pb.start();
} catch (Exception e) {
https://stackoverflow.com/questions/33940816
复制相似问题