Convert the CREATE TABLE statement for the SQL file to the DROP TABLE statement

Source: Internet
Author: User
Tags string to file stringbuffer

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

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.