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

executing scripts

shilpa reddy
Greenhorn

Joined: Dec 12, 2000
Posts: 29
Hi ,
I am trying to execute a SQL script to create some tables from my java app.
I am trying to use Runtime.
String[] cmd = new String[2];
cmd[0] ="sqlplus.exe" ;
cmd[1] = "abc.sql" ;
Process proc = Runtime.getRuntime().exec(cmd);
This spawns the SQLPlus window, but how do I run the script ?
Can this be done or do need to hardcode the create statements in my code ?
Thanks in advance.
Shilpa
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Can the script be fed as a parameter to the command?


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
shilpa reddy
Greenhorn

Joined: Dec 12, 2000
Posts: 29
How would you do this ?
Obliged if you would put down some code.
Thanks,
Shilpa
Peter Tran
Bartender

Joined: Jan 02, 2001
Posts: 783
You can feed the script in as a command line parameter. You also need to feed in the password and user id. Look up the SQL*PLUS command line parameter and it should tell you. I think it's a roundabout way to do things via JAVA. Why don't you run the script outside JAVA rather than forcing it inside the VM and executing an exec() which makes your code platform DEPENDENT.
-Peter
shilpa reddy
Greenhorn

Joined: Dec 12, 2000
Posts: 29
Hi,
The situation is to create a set of tables which the user can start off,for instance by clicking a button.
My take was to execute a set of .sql files sequentially which would contain the scripts to to this.
How would I do this outside the VM ?
And where can I look for the command line for SQL*Plus ?
Thanks,
Shilpa.
Peter Tran
Bartender

Joined: Jan 02, 2001
Posts: 783
A better approach is to do it all via JDBC. You can pass in the SQL commands via a properties file or XML configuration file. XML is probably a better mechanism in the long run, since it gives you the most flexibility.
SQL*PLUS commands can be found somewhere on the ORACLE website under documentation.
Executing a script outside the VM is not a recommend practice, since it ties you to a particular platform. What would happen if you tried to execute SQL*PLUS and it wasn't pathed correctly? Then you wouldn't have any tables created.
I would put in the work and make it all work inside your application.
my 2c.
-Peter
shilpa reddy
Greenhorn

Joined: Dec 12, 2000
Posts: 29
Thanks Peter.
Ambrose Tati
Ranch Hand

Joined: Oct 03, 2000
Posts: 55
Hi Peter,
Could you give me more info on how to use properties file and XML
configuration file?
Thanks
Ambrose
 
 
subject: executing scripts