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