# background
The use case is complete and the data is expected to be rolled back, so you want to execute the SQL rollback data
# step
Direct show code, with the help of MyBatis's Scriptrunner
/*** Execute the table backup script under XX library * *@paramTableName*/ Public Static voidRunsqlinstat (String tableName) {string ClassName= Configurations.INSTANCE.get ("Jdbc.xx.driver"); String Dburl= Configurations.INSTANCE.get ("Jdbc.xx.url"); String Dbusername= Configurations.INSTANCE.get ("Jdbc.xx.username"); String Dbpassword= Configurations.INSTANCE.get ("Jdbc.xx.password"); Try{class.forname (className); Connection Conn=drivermanager.getconnection (Dburl, Dbusername, Dbpassword); Scriptrunner Runner=NewScriptrunner (conn); Runner.setautocommit (true); String FileName= String.Format ("Src/main/resources/db/%s.sql", TableName); File File=NewFile (fileName); Try { if(File.getname (). EndsWith (". sql") {runner.setfulllinedelimiter (false); Runner.setdelimiter (";");//statement end symbol Settings Runner.setlogwriter (NULL)///log data output so that no process runner.setsendfullscript is output (false); Runner.setautocommit (true); Runner.setstoponerror (true); Runner.runscript (NewInputStreamReader (NewFileInputStream (fileName), "UTF8")); Logger.info (String.Format (""%s "Rollback succeeded", TableName)); } } Catch(Exception e) {e.printstacktrace (); } conn.close (); } Catch(SQLException e) {e.printstacktrace (); } Catch(ClassNotFoundException e) {e.printstacktrace (); } }
Java Execution SQL file