我試圖從我的Java應用程序中運行SQL腳本。這是我的代碼:使用提供的密碼在PostgreSQL上運行SQL腳本
Runtime rt = Runtime.getRuntime();
rt.exec("setx PGPASSWORD \"" + password + "\"");
String command = String.format("psql -d %s -h %s -p %s -U %s -w -f %s",
database, host, port, user, "create_tables.sql");
System.out.println("Executing command " + command);
Process p = rt.exec(String.format(command));
p.waitFor();
這將打印
psql -d routes -h localhost -p 5432 -U postgres -w -f create_tables.sql
預期。
但是在我的數據庫登錄我看到以下內容:
PSQL:fe_sendauth:沒有密碼提供
如何提供密碼,以psql
調用它的過程是什麼時候?
@Peter Mortensen您的編輯引起了一些混淆,因爲'psql'和Postgres不是一回事。 Psql只是postgres提供的shell。 – HimBromBeere