This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
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; cmd ="sqlplus.exe" ; cmd = "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
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
Joined: Dec 12, 2000
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.
Joined: Jan 02, 2001
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