Skip site navigation (1) Skip section navigation (2)

Psql syntax run within java code

From: Pei-Chieh Shen <peshen(at)cisco(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Cc: peshen(at)cisco(dot)com
Subject: Psql syntax run within java code
Date: 2004-05-06 04:21:35
Message-ID: 4.3.2.7.2.20040504162930.0243cb10@irv3-mail1.cisco.com (view raw or flat)
Thread:
Lists: pgsql-novice
Hi,

I have a problem with running a psql command from within my java application. I am pretty sure it is a syntax problem, but the same command run at the sql interface works.

Here is my syntax:

        		  strQueryForExportDump = "psql -d car -c 'select id from pegs1' "; 
                  	  objProcess=objCurrentRuntime.exec(strCommand); 
                        BufferedInputStream in = new BufferedInputStream(objProcess.getInputStream());
                        byte [] b = new byte[80];
                        in.read(b,0,30);
                        String cmdOut = new String(b);
                System.out.println("cmd out1 is " + cmdOut);

                        byte []er = new byte[580];
                        BufferedInputStream err = new BufferedInputStream(objProcess.getErrorStream());
                        err.read(er,0,580);
                        String cmdErr = new String(er);
                System.out.println("err stream is " + cmdErr);

This is the output I see from the log:

dump str is psql -d car -c 'select id from pegs1;'
cmd out1 is 
err stream is psql: warning: extra command-line argument "from" ignored
psql: warning: extra command-line argument "pegs1;'" ignored
psql: FATAL:  user "id" does not exist

Please help.

Peggy


Responses

pgsql-novice by date

Next:From: Gastón SimoneDate: 2004-05-06 12:47:53
Subject: Re: Hey Mr. PG! End my transaction, BUT KEEP MY CURSORS OPEN!!
Previous:From: Oliver FrommeDate: 2004-05-05 19:03:43
Subject: Re: Hey Mr. PG! End my transaction, BUT KEEP MY CURSORS OPEN!!

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group