Think about Using JSP to implement online backup for DB2 databases!

Source: Internet
Author: User

First of all, it should be noted that DB2's SQL statements and command line statements are separated, Unlike SQL Server 2000 which can be backed up through SQL statements, so the idea of backing up SQL server is not a line, after many attempts, I was prompted to find an unexpected mark. I had no choice but to go to the Internet to check whether there were any solutions to the problem. I was inspired to see a netizen's ideas. He said, you can use Java to call externalProgramIn fact, it is the DB2 command line tool db2cmd. EXE and then input the command to him. Below is a program I wrote. For details, refer to it and give it to myself.

 

// Backup database <br/> Public void backupdata (string URL) throws sqlexception, namingexception, <br/> ioexception {<br/>/** the URL is the root directory of the system, it can be obtained through the following statement and passed in, httpsession HS = request. getsession (); <br/> string url = HS. getservletcontext (). getrealpath ("/"); */<br/> url = URL + "dbbak //"; <br/> SQL = "backup database Anhang to '" + URL + "'"; <br/> process pro = runtime.getruntime(cmd.exe C ("db2cmd/C/W/I DB2-V "); // The environment variable of db2cmd.exe must be configured here. <br/> bufferedreader BR = new bufferedreader (New inputstreamreader (Pro. <br/> getinputstream (); <br/> printwriter PW = new printwriter (Pro. getoutputstream (); </P> <p> // stop all applications! Otherwise, an application is prompted to use the database. <br/> PW. println ("force application all"); <br/> // back up the database <br/> PW. println ("connect to Anhang user" + username + "using" + password); <br/> PW. println (SQL); <br/> PW. println ("quit"); <br/> PW. println ("exit"); <br/> PW. flush (); <br/> string line = NULL; <br/> while (line = BR. readline ())! = NULL) {<br/> system. Out. println (line); <br/>}< br/> system. Out. println ("the database is backed up successfully! "); <Br/>}

Related Article

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.