1 Packagecom.csii.pweb.query.action;2 3 ImportJava.io.BufferedReader;4 Importjava.io.FileNotFoundException;5 ImportJava.io.FileReader;6 Importjava.io.IOException;7 Importjava.util.ArrayList;8 Importjava.util.List;9 Ten One Public classJavafile { A Public Static voidMain (string[] args) { - Try { - //read file content from file theStringBuffer sb=NewStringBuffer (""); - -FileReader reader =NewFileReader ("D:/t/workflow.sql"); -BufferedReader br =NewBufferedReader (reader); + -String str =NULL; + FinalString Markstart = "CREATE TABLE"; AList<string> Tablenames =NewArraylist<string>(); at while(str = br.readline ())! =NULL) { -str = str.touppercase (). Trim ();//capitalize and remove both spaces - if(Str.startswith (Markstart) &&!str.startswith ("--)") {//non-annotated build table statement -str = str.substring (Markstart.length ()). Replace (' (', ');//take a table name -Tablenames.add ("DROP TABLE" + str.trim () + ";"); - //System.out.println (str); in } - } to + br.close (); - reader.close (); the //Reverse * for(intI=tablenames.size ()-1; i>=0;i--) { $String name =Tablenames.get (i);Panax NotoginsengSb.append (name). Append ("\ n"); - } theSystem.out.println ("--------------Start---------------"); + System.out.println (SB); ASystem.out.println ("--------------End---------------" +tablenames.size ()); the + //write string to file - //FileWriter writer = new FileWriter ("C://test2.txt "); $ //bufferedwriter bw = new BufferedWriter (writer); $ //Bw.write (sb.tostring ()); - // - //bw.close (); the //writer.close (); - }Wuyi Catch(FileNotFoundException e) { the e.printstacktrace (); - } Wu Catch(IOException e) { - e.printstacktrace (); About } $ } -}
The CREATE TABLE statement for the
Convert SQL file is a drop TABLE statement