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/>}