dbTalk Databases Forums  

Psql syntax run within java code

comp.databases.postgresql.novice comp.databases.postgresql.novice


Discuss Psql syntax run within java code in the comp.databases.postgresql.novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Pei-Chieh Shen
 
Posts: n/a

Default Psql syntax run within java code - 05-05-2004 , 11:21 PM






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


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)


Reply With Quote
  #2  
Old   
joseph speigle
 
Posts: n/a

Default Re: Psql syntax run within java code - 05-06-2004 , 08:03 PM






I don't know how old this message is, but looks like it needs a username to connect as? Just try

psql -d car -U username -c 'select id from pegs1';

There was also a post yesterday about being able to put the pass in a .pgpass file, if it would fail for lack of a password

Quote:
strQueryForExportDump = "psql -d car -c 'select id from pegs1' ";
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


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo (AT) postgresql (DOT) org)
--
joe speigle
www.sirfsup.com

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.