*
The moose likes JDBC and the fly likes executing an sql through java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "executing an sql through java" Watch "executing an sql through java" New topic
Author

executing an sql through java

Anil Bansal
Greenhorn

Joined: Jun 18, 2009
Posts: 4

Hi All,
I also wanted to execute an sql script through java but had one more requirement. I wanted to ensure that the password that i am using to connect to the database as well as the arguments to the script are not visible through ps commands.
Can you suggest me a way in which i can redirect the password as well as the arguments through a file using java.
something like:
runtime.exec(sqlplus system@db @some.sql <tmp)
where tmp is the temporary file and has the password to connect to the db as well as the arguments required by the sql file.
This is not working in java through runtime command but the same kind of thing works in a shell script.

Is there any other better way of achieving the same.

Thanks,
Anil
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41508
    
  53
This is not working in java through runtime command but the same kind of thing works in a shell script.

I suspect that it will work fine once you get the details right. For starters, use Runtime.exec(String[]) instead of Runtime.exec(String). Then, read Daconta's article "When Runtime.exec() doesn't" - it explains what to watch out for.


Ping & DNS - my free Android networking tools app
Anil Bansal
Greenhorn

Joined: Jun 18, 2009
Posts: 4
Hi,
Thanks a lot for redirecting to that article and after reading that article i understood that we cannot use it the way i was trying to use it.
But the article does not show the way i can successfully execute my command.
I want to first connect to a database using sqlplus command as well as at the same time hide the password used to connect, then run an sql with the required arguments as well as hide all those arguments.
Can you please guide me as to how to do this?

Anil Bansal
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41508
    
  53
The article has plenty of examples; what is missing to adapt it to your situation?
Anil Bansal
Greenhorn

Joined: Jun 18, 2009
Posts: 4
Hi,
If i add something to the process.getOutputStream then i am able to get the password to connect to the db. But the problem here is i cannot send multiple arguments through the same stream.
For instance, if i just had to pass only the password to connect to the db through the proc.getOutputStream, it is working fine and executing the sql as well, but if i want to pass the arguments of the sql script also through the same stream it does not work as it considers everything as one string.
This is the problem that i have.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: executing an sql through java