i am trying to execute a .sql file in java. It works fine when i am giving exit at the end of the .sql file. Is there any solution to run without giving exit at the end of file, please reply me. Thanks in advance.
My java code:
-------------
My java code:
-------------
Code:
import java.io.BufferedReader; import java.io.File; import java.io.FileFilter; import java.io.IOException; import java.io.InputStreamReader; public class StackFlow { private static String script_location = ""; private static String file_extension = ".sql"; private static ProcessBuilder processBuilder =null; public static void main(String[] args) { try { File file = new File("D:/script1"); File [] list_files= file.listFiles(new FileFilter() { public boolean accept(File f) { if (f.getName().toLowerCase().endsWith(file_extension)) return true; return false; } }); int count=0; for (int i = 0; i<list_files.length;i++){ script_location = "@" + list_files[i].getAbsolutePath();//ORACLE processBuilder = new ProcessBuilder("sqlplus","ESB22/ESB22", script_location); //ORACLE //script_location = "-i" + list_files[i].getAbsolutePath(); // processBuilder = new ProcessBuilder("sqlplus", "-Udeep-Pdumbhead-Spc-de-deep\\sqlexpress-de_com",script_location); processBuilder.redirectErrorStream(true); Process process = processBuilder.start(); BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream())); String currentLine = null; while ((currentLine = in.readLine()) != null) { System.out.println(" " + currentLine); // System.out.println("Line----"+count++); } } } catch (IOException e) { e.printStackTrace(); }catch(Exception ex){ ex.printStackTrace(); } } }
Comment