Java executes the uploaded SQL script file

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.