Novice! How to run pg_dump from within Java?

Поиск
Список
Период
Сортировка
От Damian C
Тема Novice! How to run pg_dump from within Java?
Дата
Msg-id 2bbc8f530607251949r3dda6d3fudf6d57dd6a1d673a@mail.gmail.com
обсуждение исходный текст
Ответы Re: Novice! How to run pg_dump from within Java?  ("Michael Swierczek" <mike.swierczek@gmail.com>)
Список pgsql-novice
Hello,

We have a Java project that is developing a small business app and
using Hibernate & Postgres for persistence.  It all works like a dream
until we need to know anything about Postgres!!  It is obviously a
"feather in the cap" of Postgres that "so many (Java developers) can
do so much while knowing so little".

I need to perform the world's simplest task: Create a pg dump from within Java.

Of course we do this easily using pgAdminIII, but I need to automate
it for our Users. I notice that pgAdmin uses a command line like this
...
<snip>
C:\Program Files\PostgreSQL\8.1\bin\pg_dump.exe -i -h localhost -p
5432 -U pgsuperuser -F c -b -v -f "D:\PG_26jul06.backup" devdb
</snip>

We use "ProcessBuilder" to launch the  "pg_dump.exe" program. It takes
an List of Strings in its constructor (including appropriate escape
characters) ...
<snip>
List<String> cmds = new ArrayList<String>();
cmds.add("C:\\Program Files\\PostgreSQL\\8.1\\bin\\pg_dump.exe");
cmds.add("-i");
cmds.add("-h");
cmds.add("localhost");
cmds.add("-p");
cmds.add("5432");
cmds.add("-U");
cmds.add("pgsuperuser");
cmds.add("-F");
cmds.add("c");
cmds.add("-b");
cmds.add("-v");
cmds.add("-f");
cmds.add("\"D:\\PG_26jul06A.backup\"");
cmds.add("devdb");
Process process = new ProcessBuilder(cmds).start();
</snip>

Now this DOES work in that pg_dump.exe is invoked, and a new file is
created at the correct location. However, the file size is zero
(instead of the pgAdminIII version that is 47K)

Any suggestions on what I'm doing wrong,
or any pointers for a better way to do this??

Many thanks,
-Damian

В списке pgsql-novice по дате отправления:

Предыдущее
От: Sean Davis
Дата:
Сообщение: Re: Installation "baby" steps (next steps)?
Следующее
От:
Дата:
Сообщение: Re: Installation "baby" steps (next steps)?