Java automatic backup MySQL database (reproduced)

Source: Internet
Author: User


1 PackageCom.learn4j.bat;2 3 Public classBackup {4 PrivateString user_name;//Database user name5 PrivateString USER_PSW;//Database Password6 PrivateString db_name;//the name of the database that needs to be backed up7 PrivateString host_ip;//Host IP8 PrivateString User_charset;//Character Set9 PrivateString Backup_path;//the path where the backup file is storedTen PrivateString stmt;//Command One A PublicBackup (String user_name, String user_psw, String db_name, - string host_ip, String user_charset, String backup_path) { - This. User_name =user_name; the This. USER_PSW =USER_PSW; - This. db_name =db_name; - //host IP; - if(Host_ip = =NULL|| Host_ip.equals ("")) + This. host_ip = "localhost";//default is native - Else + This. host_ip =host_ip; A //Character Set at if(User_charset = =NULL|| User_charset.equals ("")) - This. User_charset = "";//The default is the set of character sets at installation time - Else - This. User_charset = "--default-character-set=" +User_charset; - This. Backup_path =Backup_path; - This. stmt = "C:\\wamp\\bin\\mysql\\mysql5.5.20\\bin\\mysqldump" in+ This. db_name + "-H" + This. host_ip + "-u" + This. User_name -+ "-P" + This. USER_PSW + This. User_charset + "--result-file=" to+ This. Backup_path; + } - the Public BooleanBackup_run () { * BooleanRun_result =false; $ Try {Panax NotoginsengRuntime.getruntime (). EXEC ( This. stmt); -Run_result =true; the}Catch(Exception e) { + e.printstacktrace (); A } the returnRun_result; + } - $ Public Static voidMain (string[] args) { $Backup backup =NewBackup ("root", "123456", "Student",NULL, "UTF8", -"D:\\test.sql"); - Booleanresult =Backup.backup_run (); the if(Result) -SYSTEM.OUT.PRINTLN ("Backup succeeded");Wuyi } the}

Original link: http://blog.sina.com.cn/s/blog_59ae45de0100ds17.html

Java automatic backup MySQL database (reproduced)

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.