The Sqlplus execution SQL file was started by executing cmd in Java, but it was later discovered that once the script was executed, it would wait until it was finished and not shut down. To facilitate the execution of SQL scripts for the implementation of the SqlExec class that calls Ant. The original code is as follows, I upload the SQL script file from the front end of the server to perform the background service:
sqlexec sqlexec = new SQLExec (); //set the database parameter sqlexec.setdriver (" Oracle.jdbc.driver.OracleDriver "); sqlexec.seturl (" jdbc:oracle:thin:@192.168.5.110:1521 : Tcis3 "); sqlexec.setuserid (" Bam30 "); sqlexec.setpassword (" Bam30 "); sqlexec.setsrc (New file (" D:\\test.sql ")); // Sqlexec.setonerror ((Sqlexec.onerror) (Enumeratedattribute.getinstance (sqlexec.onerror.class, "Abort")); sqlexec.setprint (TRUE); //sets whether output //output to a file sql.out Do not set this property, default output to console sqlexec.setoutput (New file ("D:/sql.log"); sqlexec.setproject (New project ()); // to specify this property, it will be an error Sqlexec.execute ();
The above code will execute the SQL script. For the sake of simplicity, my capture of the exception is done through a try catch, without taking the exception stream, then catching the error message and then returning it, and the specific code is not listed. The main is the execution of SQL script, by contrast, the personal feel that this way is also good, more importantly, to avoid the problem caused by the platform Java call cmd failure and so on.
This article is from "Rookie Learning" blog, please make sure to keep this source http://biyusheng.blog.51cto.com/2626140/1547314
Java executes the uploaded SQL script file