Java Execution SQL file

Source: Internet
Author: User

To define database connection properties:

static string Divername= "Oracle.jdbc.driver.OracleDriver"; static string url = "jdbc:oracle:thin:@192.168.90.11:1521: Ucap "; static string user=" armyoa73015 "; static string pwd =" armyoa73015 ";

1. Method of execution (dependent on Ant.jar):

static String FileName = "D:\\workspace\\huzhou\\jd-txt73015\\sql\\f_xxyr_xlcjdj.sql";p ublic static void Runsqlfile () {SQLExec SQLExec = new SQLExec (); Sqlexec.setdriver (divername); Sqlexec.seturl (URL); sqlexec.setuserid (user); Sqlexec.setpassword (PWD); SQLEXEC.SETSRC (new File), sqlexec.setencoding ("GBK");D elimitertype dt = new Delimitertype ();d t.setvalue ("Row"), Sqlexec.setdelimitertype (DT); Sqlexec.setdelimiter ("/"); Sqlexec.setkeepformat (True); Sqlexec.setproject (new Project ()); Sqlexec.execute ();}

2. Method of execution (dependent on Mybatis-3.0.6.jar):

public static void RunSqlFile1 () {try {class.forname (divername); Connection conn = drivermanager.getconnection (URL, user, pwd); Scriptrunner runner = new Scriptrunner (conn); Runner.setautocommit (true); File File = new file (fileName), try {if (File.getname (). EndsWith (". sql")) {Runner.setfulllinedelimiter (true); Runner.setdelimiter ("# #"); Runner.setsendfullscript (false); Runner.setautocommit (true); Runner.setstoponerror ( true) Runner.runscript (new InputStreamReader (New FileInputStream (FileName), "GBK"));}} catch (Exception e) {e.printstacktrace ();} Conn.close ();} catch (SQLException e) {e.printstacktrace ()} catch (ClassNotFoundException e) {//TODO auto-generated catch Blocke.print StackTrace ();}}

Note: After this method executes, stored procedures, triggers, functions, and packages are in an invalid state. The reason is unknown???




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java Execution SQL 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.