⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 backupdb2.java

📁 一套DB2 7到8版本的程序。内附创建ZIP的JAVA类
💻 JAVA
字号:
package com.highsoft.bus;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

public class BackupDB2 {

	public List Backup() {
		List pathandname=new ArrayList();
		Process pro;
		Properties proper=new Properties();
		Properties path=new Properties();
		try {
			path.load(BackupDB2.class.getResourceAsStream("path.properties"));
			pro = Runtime
					.getRuntime()
					.exec("\"D:\\Program Files\\IBM\\SQLLIB\\bin\\db2cmd.exe\" /c /w /i db2 -v");
			//path.getProperty("ibm.path")
			java.io.BufferedReader br = new java.io.BufferedReader(
					new java.io.InputStreamReader(pro.getInputStream()));
			java.io.PrintWriter pw = new java.io.PrintWriter(pro
					.getOutputStream());

			//   把所有的应用全干掉!!,否则会提示有应用程序正在使用此数据库 
			pw.println("force   application   all");
			pw.println("backup   database  "+path.getProperty("database.name")+"   user  "+path.getProperty("database.ibm.name")+"   using  "+path.getProperty("database.ibm.password")+"   to   "+path.getProperty("database.ibm.path")+"   with   2   buffers   buffer   1024");
			pw.println("quit");
			pw.println("exit");
			pw.flush();

			String line = null;
			while ((line = br.readLine()) != null) {
				if(line.startsWith("备份成功"))
				{
					String newa=line.substring(17,25);
					String newb=line.substring(25,31);
					pathandname.add(newa);
					pathandname.add(newb);
				}
				System.out.println(line);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			System.out.println(e.getMessage());
			e.printStackTrace();
		}
		return pathandname;
	}
	
	public boolean deldate(String sql)
	{
		boolean flag=false;
		Process pro;
		Properties proper=new Properties();
		Properties path=new Properties();
		try {
			path.load(BackupDB2.class.getResourceAsStream("path.properties"));
			pro = Runtime
					.getRuntime()
					.exec("\"D:\\Program Files\\IBM\\SQLLIB\\bin\\db2cmd.exe\" /c /w /i db2 -v");
			java.io.BufferedReader br = new java.io.BufferedReader(
					new java.io.InputStreamReader(pro.getInputStream()));
			java.io.PrintWriter pw = new java.io.PrintWriter(pro
					.getOutputStream());

			//   把所有的应用全干掉!!,否则会提示有应用程序正在使用此数据库 
			//pw.println("force   application   all");
			pw.println("connect to "+path.getProperty("database.name")+"");
			pw.println(sql);
			pw.println("quit");
			pw.println("exit");
			pw.flush();

			String line = null;
			while ((line = br.readLine()) != null) {
				System.out.println(line);
			}
			flag=true;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			System.out.println(e.getMessage());
		}
		return flag;
	}
	public static void main(String[] args) {
		BackupDB2 back=new BackupDB2();
		//List list=back.Backup();
		//back.deldate("import from d:\\xx.txt of del replace into root.t_user");
		Properties path=new Properties();
		try {
			path.load(BackupDB2.class.getResourceAsStream("path.properties"));
			System.out.println(path.getProperty("ibm.path"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -