Java 调用bat执行的备份Oracle数据库 类(三)

2014-11-24 18:12:07 · 作者: · 浏览: 2
.formatDbColumn(map.get("PROJ_ID")) 这个是即将导入 项目的 新的父id
String proj_id =getProjId(map);
//创建个缓存 数据集
List tmpBat=new ArrayList();
//获取模板 文件
File Afile=new File(StringUtil.formatDbColumn(map.get("Paths"))+"\\processBat\\dp\\impClearing.sql");
//生成空白的bat临时文件
File Bfile=new File(StringUtil.formatDbColumn(map.get("Paths"))+"\\impClearing.sql");
//申明读取缓冲器
BufferedReader br=null;
try {
//设置读取缓冲器 文件指向
br = new BufferedReader(new InputStreamReader(new FileInputStream(Afile)));
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
try {
try {
while(br.ready())//判断是否还有可读信息
{
//读取一行数据
String str=br.readLine().toString();
//设置备份文件名 %proj_id%
str = str.replace("%proj_id%", proj_id);
tmpBat.add(str);
}
//关闭缓冲器
br.close();
} catch (IOException e) {
try {
br.close();
} catch (IOException e1) {
e1.printStackTrace();
}
e.printStackTrace();
}

//设定写数据缓冲器 文件指向
PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(Bfile)),true);
for(String str : tmpBat)
{
//按行写入
pw.println(str);
}
pw.println("exit");
//关闭缓冲器
pw.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}

return "";
}



/**
* 生成导入 项目的id 和 更新语句
* @param map
* @return
*/
private static String getProjId(Map map)
{
String FilePath=StringUtil.formatDbColumn(map.get("FilePath"));
FilePath = FilePath.substring(FilePath.lastIndexOf("-")+1, FilePath.lastIndexOf('.'));

File UpParentId=new File(StringUtil.formatDbColumn(map.get("Paths"))+"\\UpdateParentId.sql");
PrintWriter pw;
try {
pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(UpParentId)),true);
pw.println("update cm_proj t set t.parent_proj_id='"+StringUtil.formatDbColumn(map.get("PROJ_ID"))+"',t.parent_path=('"
+getProjPath(StringUtil.formatDbColumn(map.get("PROJ_ID")))+"'||';'||'"+FilePath+"') where t.proj_id='"+FilePath+"';");
pw.println("commit;");
pw.println("exit");
//关闭缓冲器
pw.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return FilePath;
}

/**
* 获取父级路径
* @param map
* @return
*/
private static String getProjPath(String proj_id)
{
String projPath=null;
Connection conn=null;
try {
conn=DBConn.getConnection("***");//该方法自己写
projPath = (String)DBUtil.getResultFieldValue(conn, "select parent_path from cm_proj where proj_id ='"+proj_id+"'");
conn.close();
} catch (SQLException e) {
Logger.error(e);
}finally{
try
{
conn.close();
} catch (SQLException e)
{
Logger.error(e);
}
}
return projPath;
}


}