搜索
首页数据库mysql教程根据上传到suse9服务器的Oracle脚本创建Oracle数据库及执行用户

需求: 用户通过平台上传Oracle脚本(创建表、视图等但不包括直接创建表空间的脚本)到suse服务器,程序需要在Oracle数据库服务器上创建一个对应的表空间,并在该表空内根据用户的脚本来生成表、视图等。 解决办法: 思想 : 通过匹配sql模板文件,来每次创建

         需求:

      用户通过平台上传Oracle脚本(创建表、视图等但不包括直接创建表空间的脚本)到suse服务器,程序需要在Oracle数据库服务器上创建一个对应的表空间,并在该表空内根据用户的脚本来生成表、视图等。

        解决办法:

        思想通过匹配sql模板文件,来每次创建唯一的数据库表空间,然后通过linux的shell脚本来连接到数据库服务器执行用户的脚本文件,最终由java程序来执行该shell脚本文件,并根据shell产生的日志判断是否执行成功,如不成功则调用删除的方法进行删除表空间的操作。

       1,编写创建Oracle表空间的SQl模板文件(createdbspace.sql)

        createdbspace.sql内容如下:

--%1--dba用户名(配置文件)
--%2--dba密码(配置文件)
--%3--实例名(配置文件)
--%4--表空间名称(传参)
--%5--表空间目录(配置文件)
--%6--初始空间大小(配置文件)
--%7--空间增长大小(配置文件)
--%8--最大空间大小(传参)
--%9--创建用户名(传参)
--%10--创建用户密码(传参)
--%a--临时表空间(配置文件)


create tablespace 4% datafile '5%/4%.dbf' size 6% M REUSE AUTOEXTEND ON NEXT 7% M MAXSIZE 8% M DEFAULT STORAGE ( INITIAL 64K NEXT 4M MINEXTENTS 1 MAXEXTENTS UNLIMITED PCTINCREASE 0 )
;

create user 9% identified by 10% default tablespace 4% temporary tablespace a% profile default
;

grant connect,resource to 9%
;

revoke unlimited tablespace from 9%
;

alter user 9% quota unlimited on 4%
;
commit
;
exit;

 

      

       2,编写相应安装所需执行的shell脚本(install.sh)

          install.sh内容如下:

#!/bin/sh

#实例名
sid=1%

#新创建的数据库用户名
system=2%

#新创建的数据库密码
systemPass=3%

#log日志目录
logpath=4%

#log日志名
logfile=5%

#执行的sql名称
sqlfile=7%

#创建表空间的脚本目录
sqlspacepath=8%

#执行表空间的sql名称
sqlspacefile=9%


#dba数据库用户名
dbasystem=b%

#dba数据库密码
dbasystemPass=c%

#创建日志目录
mkdir $logpath   2>/dev/null

echo start install dbspace script ... >$logfile

#在数据库脚本末尾追加exit,保证脚本执行完成后退出
echo 'exit;' >>$sqlfile

#oracle环境变量
. /home/oracle/.bash_profile 2>>$logfile

#创建表空间和用户脚本
sqlplus $dbasystem/$dbasystemPass@$sid @$sqlspacepath/$sqlspacefile   >>$logfile
echo start install db script  >>$logfile

#执行数据库脚本
export NLS_LANG='SIMPLIFIED CHINESE_CHINA.ZHS16GBK'
sqlplus $system/$systemPass@$sid @$sqlfile      >>$logfile
export NLS_LANG=AMERICAN_AMERICA.utf8

echo end install db script. >>$logfile

 

     

       3, 有安装就可以删除所以还要编写一个删除表空间的sql脚本(dropspace.sql)

         dropspace.sql内容如下:

 

drop user 1% cascade;
drop tablespace 2% including contents and datafiles cascade constraints  ;
commit;
exit;

 

        4,编写相应的执行删除任务的shell脚本(unistall.sh)

           unistall.sh内容如下:

#!/bin/sh

#实例名
sid=1%

#log日志目录
logpath=4%

#log日志名
logfile=5%

#删除表空间的脚本目录
sqlspacepath=8%

#删除表空间的sql名称
sqlspacefile=9%

#dba数据库用户名
dbasystem=b%

#dba数据库密码
dbasystemPass=c%

#创建日志目录
mkdir $logpath   2>/dev/null

echo start delete dbspace script ... >$logfile

#oracle环境变量
. /home/oracle/.bash_profile 2>>$logfile

#创建表空间和用户脚本
sqlplus $dbasystem/$dbasystemPass@$sid @$sqlspacepath/$sqlspacefile               >>$logfile

echo end delete db script . >>$logfile

 

 

       5,相应的java源程序(其中像上传、下载、继承的类等代码段是内部封装的看不出所以然但本身对此程序需要实现的功能并无大碍)

         SqlInstall .java源文件内容:

 public class SqlInstall extends DynamicObjectBaseDS implements ISqlInstall{
 IUcmServerDS ucmServerDS =null;
 IUcmContentBufDS ucmContentBufDS=null;
 IUcmContentDS ucmContentDS=null;
 
 //获取ftp配置信息
 static String ftpip =ApplicationGlobalResource.getInstance().getValueByKey(
 "paasfile.ftpip");
 static String ftpport =ApplicationGlobalResource.getInstance().getValueByKey(
 "paasfile.ftpport");
 //FTP端口
 static int port = Integer.parseInt(ftpport);
 //FTP用户名
 static String ftpusername = ApplicationGlobalResource.getInstance()
 .getValueByKey("paasfile.ftpusername");
 //FTP密码
 static String ftppassword = ApplicationGlobalResource.getInstance()
 .getValueByKey("paasfile.ftppassword");
 
 //sh脚本上传的文件夹
 static String shfilepath = ApplicationGlobalResource.getInstance()
 .getValueByKey("dbspace.shfilepath");
 
 //sh脚本上传的文件夹
 static String spaceshfilepath = ApplicationGlobalResource.getInstance()
 .getValueByKey("dbspace.scriptoutPath");
 
 //dba用户名(配置文件)
 static String dbaname= ApplicationGlobalResource.getInstance()
 .getValueByKey("dbspace.dbaname");
 //dba密码(配置文件)
 static String dbapwd=ApplicationGlobalResource.getInstance()
 .getValueByKey("dbspace.dbapwd");
 //服务名(配置文件)
 static String dbasid=ApplicationGlobalResource.getInstance()
 .getValueByKey("dbspace.dbasid");
 //数据库IP(配置文件)
 static String dbIP=ApplicationGlobalResource.getInstance()
 .getValueByKey("dbspace.dbIP");
 //数据库端口(配置文件)
 static String dbport=ApplicationGlobalResource.getInstance()
 .getValueByKey("dbspace.dbport");
 //数据库类型(配置文件)
 static String dbtype=ApplicationGlobalResource.getInstance()
 .getValueByKey("dbspace.dbtype");
 //数据库版本(配置文件)
 static String dbversion=ApplicationGlobalResource.getInstance()
 .getValueByKey("dbspace.dbversion");
 //数据库实例名(配置文件)
 static String dbainstanceid=ApplicationGlobalResource.getInstance()
 .getValueByKey("dbspace.dbainstanceid");
 
 
 /**
  * 获得参数生成创建表空间的SQL脚本,并上传至服务器
  * @param spacename  表空间名称
  * @param spacesize  表空间大小
  * @param createuser 新创建的用户
  * @param createpwd  新创建的密码
  * @return 创建的文件名
  */
 public String createdbSpaceSql(String spacename,String spacesize,String createuser,String createpwd){

  //表空间存放目录(配置文件)
  String spaceposition=ApplicationGlobalResource.getInstance()
  .getValueByKey("dbspace.spaceposition");
  //初始空间大小(配置文件)
  String spaceinitsize=ApplicationGlobalResource.getInstance()
  .getValueByKey("dbspace.spaceinitsize");
  //空间增长大小(配置文件)
  String spacestepsize=ApplicationGlobalResource.getInstance()
  .getValueByKey("dbspace.spacestepsize");
  //临时表空间(配置文件)
  String tempspace=ApplicationGlobalResource.getInstance()
  .getValueByKey("dbspace.tempspace"); 
  
  //创建表空间的脚本上传目录
  String sqlspacepath=ApplicationGlobalResource.getInstance()
  .getValueByKey("dbspace.shfilepath");
  
  
  //创建表空间模板文件本地读取路径
  String sqlspaceinPath=ApplicationGlobalResource.getInstance()
  .getValueByKey("dbspace.sqlspaceinPath");  
  //创建表空间文件输出本地路径
  String sqlspaceoutPath=ApplicationGlobalResource.getInstance()
  .getValueByKey("dbspace.scriptoutPath");
    
  // 解读模板文件,并生成sql脚本文件
  SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMddHHmmss");
  String date = sdf2.format(new Date());
  String number=String.valueOf((int)(Math.random()*1000));
  String filefullname="create"+date+number;
  
  File file = new File(sqlspaceinPath);//表空间模板文件
  File shfile = new File(sqlspaceoutPath + "/"+filefullname + ".sql");  // 创建文件流按照模板匹配后的创建表空间文件路径
  
  PrintStream ps = null;
  InputStreamReader isr = null;
  BufferedReader br = null;
  
  try {
   ps = new PrintStream(shfile,"UTF-8");
   isr = new InputStreamReader(new FileInputStream(file),"UTF-8");
   br = new BufferedReader(isr);
   String st = br.readLine();
   while (st != null) {
    //脚本变量替换
    st = st.replaceAll("1%",dbaname);
    st = st.replaceAll("2%",dbapwd);
    st = st.replaceAll("3%",dbasid);
    st = st.replaceAll("4%",spacename);
    st = st.replaceAll("5%",spaceposition);
    st = st.replaceAll("6%",spaceinitsize);
    st = st.replaceAll("7%",spacestepsize);
    st = st.replaceAll("8%",spacesize);
    st = st.replaceAll("9%",createuser);
    st = st.replaceAll("10%",createpwd);
    st = st.replaceAll("a%",tempspace);
    ps.println(st);
    st = br.readLine();
   }
  } catch (Exception e) {
   e.printStackTrace();
   return "";
  } finally {
   //关闭
   try {
    if (br != null) {
     br.close();
    }
    if (isr != null) {
     isr.close();
    }
    if (ps != null) {
     ps.close();
    }
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
  //获得生成的sql的文件名
  String filename=shfile.getName();
  

  //返回文件名
  return filename;
 }
 
 
 
 
 /**
  * 根据参数创建可执行的sh脚本,并且上传
  * @param sid 实例名
  * @param username 数据库用户名
  * @param password 数据库密码
  * @param sqlfile 执行的数据库脚本文件名
  * @param sqlspacefile 执行数据库创建表空间的文件名
  * @param logfile LOG文件名,由系统生成
  * @return
  */
 public   String createInstallSh(String createuser,String createpwd,String sqlfile,String sqlspacefile,String logfile){
  //log日志目录
  String logpath=ApplicationGlobalResource.getInstance()
  .getValueByKey("dbspace.logpath");
  
  //创建表空间的sh脚本目录
  String sqlspacepath=ApplicationGlobalResource.getInstance()
  .getValueByKey("dbspace.shfilepath");
  //sh模板文件读取路径
  String shinPath=ApplicationGlobalResource.getInstance()
  .getValueByKey("dbspace.shspaceinPath");
  //sh文件输出路径
  String shoutPath=ApplicationGlobalResource.getInstance()
  .getValueByKey("dbspace.scriptoutPath");
  
  // 解读模板文件,并生成sh脚本文件
  SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMddHHmmss");
  String date = sdf2.format(new Date());
  String number=String.valueOf((int)(Math.random()*1000));
  String filefullname="install"+date+number;
  File file = new File(shinPath);
  // 创建文件流
  File shfile = new File(shoutPath + filefullname + ".sh");
  PrintStream ps = null;
  InputStreamReader isr = null;
  BufferedReader br = null;
  try {
   ps = new PrintStream(shfile,"UTF-8");
   isr = new InputStreamReader(new FileInputStream(file),"UTF-8");
   br = new BufferedReader(isr);
   String st = br.readLine();
   while (st != null) {
    //脚本变量替换    
    st = st.replaceAll("1%",dbasid);
    st = st.replaceAll("2%",createuser);
    st = st.replaceAll("3%",createpwd);
    st = st.replaceAll("4%",logpath);
    st = st.replaceAll("5%",logpath+"/"+logfile);   
    st = st.replaceAll("7%",sqlfile);
    st = st.replaceAll("8%",sqlspacepath);
    st = st.replaceAll("9%",sqlspacefile);    
    st = st.replaceAll("b%",dbaname);
    st = st.replaceAll("c%",dbapwd);
    ps.println(st);
    st = br.readLine();
   }
  } catch (Exception e) {
   e.printStackTrace();
   return "";
  } finally {
   //关闭
   try {
    if (br != null) {
     br.close();
    }
    if (isr != null) {
     isr.close();
    }
    if (ps != null) {
     ps.close();
    }
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
  
  //获得生成的sh文件的文件名
  String filename=shfile.getName();
  
  System.out.println("赋权前文件大小:"+new File(filename).length());
  //给文件赋权 
  this.chmodrun(filename);
  System.out.println("赋权后文件大小:"+new File(filename).length());

  //返回文件名
  return filename;
 };


 public String createCheckLogSh(String logfile){

  //sh模板文件读取路径
  String shinPath=ApplicationGlobalResource.getInstance().getValueByKey("dbspace.checklogsh");
  //sh文件输出路径
  String shoutPath=shfilepath;
  
  // 解读模板文件,并生成sh脚本文件
  SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMddHHmmss");
  String date = sdf2.format(new Date());
  String number=String.valueOf((int)(Math.random()*1000));
  String filefullname="checkLog"+date+number;
  
  File file = new File(shinPath);
  File shfile = new File(shoutPath + filefullname + ".sh");
  PrintStream ps = null;
  InputStreamReader isr = null;
  BufferedReader br = null;
  try {
   ps = new PrintStream(shfile,"UTF-8");
   isr = new InputStreamReader(new FileInputStream(file),"UTF-8");
   br = new BufferedReader(isr);
   String st = br.readLine();
   while (st != null) {
    //脚本变量替换    
    st = st.replaceAll("1%",logfile);
    ps.println(st);
    st = br.readLine();
   }
  } catch (Exception e) {
   e.printStackTrace();
   return "";
  } finally {
   //关闭
   try {
    if (br != null) {
     br.close();
    }
    if (isr != null) {
     isr.close();
    }
    if (ps != null) {
     ps.close();
    }
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
  
  //获得生成的sh文件的文件名
  String filename=shfile.getName();
  
  System.out.println("赋权前文件大小:"+new File(filename).length());
  //给文件赋权 
  this.chmodrun(filename);
  System.out.println("赋权后文件大小:"+new File(filename).length());

  //返回文件名
  return filename;
  
 }
 
 /**
  * 获得参数生成删除表空间的SQL脚本,并上传至服务器
  * @param spacename  表空间名称
  * @param createuser 新创建的用户
  * @return 创建的文件名
  */
 public String dropdbSpaceSql(String spacename,String createuser){
 
  //删除表空间的脚本上传目录
  String sqlspacepath=ApplicationGlobalResource.getInstance()
  .getValueByKey("dbspace.shfilepath");
  
  //删除表空间模板文件读取路径
  String sqlspaceinPath=ApplicationGlobalResource.getInstance()
  .getValueByKey("dbspace.dropspacesql");
  //创建表空间文件输出路径
  String sqlspaceoutPath=ApplicationGlobalResource.getInstance()
  .getValueByKey("dbspace.scriptoutPath");
    
  // 解读模板文件,并生成sh脚本文件
  SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMddHHmmss");
  String date = sdf2.format(new Date());
  String number=String.valueOf((int)(Math.random()*1000));
  String filefullname="drop"+date+number;
  File file = new File(sqlspaceinPath);
  // 创建文件流
  File shfile = new File(sqlspaceoutPath + "/"+filefullname + ".sql");
  PrintStream ps = null;
  InputStreamReader isr = null;
  BufferedReader br = null;
  try {
   ps = new PrintStream(shfile,"UTF-8");
   isr = new InputStreamReader(new FileInputStream(file),"UTF-8");
   br = new BufferedReader(isr);
   String st = br.readLine();
   while (st != null) {
    //脚本变量替换
    st = st.replaceAll("1%",createuser);
    st = st.replaceAll("2%",spacename);
    ps.println(st);
    st = br.readLine();
   }
  } catch (Exception e) {
   e.printStackTrace();
   return "";
  } finally {
   //关闭
   try {
    if (br != null) {
     br.close();
    }
    if (isr != null) {
     isr.close();
    }
    if (ps != null) {
     ps.close();
    }
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
  //获得生成的sh文件的文件名
  String filename=shfile.getName();  

  //返回文件名
  return filename;
 }
 
 
 
 
 /**
  * 根据参数创建删除表空间的sh脚本,并且上传
  * @param sid 实例名
  * @param username 数据库用户名
  * @param password 数据库密码
  * @param sqlfile 执行的数据库脚本文件名
  * @param sqlspacefile 执行删除数据库创建表空间的文件名
  * @return
  */
 public   String dropInstallSh(String sqlspacefile,String logfile){
  //log日志目录
  String logpath=ApplicationGlobalResource.getInstance()
  .getValueByKey("dbspace.logpath");
  //删除表空间的脚本目录
  String sqlspacepath=ApplicationGlobalResource.getInstance()
  .getValueByKey("dbspace.shfilepath");
  //sh模板文件读取路径
  String shinPath=ApplicationGlobalResource.getInstance()
  .getValueByKey("dbspace.dropspacesh");
  //sh文件输出路径
  String shoutPath=ApplicationGlobalResource.getInstance()
  .getValueByKey("dbspace.scriptoutPath");
  
  // 解读模板文件,并生成sh脚本文件
  SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMddHHmmss");
  String date = sdf2.format(new Date());
  String number=String.valueOf((int)(Math.random()*1000));
  String filefullname="uninstall"+date+number;
  File file = new File(shinPath);
  // 创建文件流
  File shfile = new File(shoutPath + filefullname + ".sh");
  PrintStream ps = null;
  InputStreamReader isr = null;
  BufferedReader br = null;
  try {
   ps = new PrintStream(shfile,"UTF-8");
   isr = new InputStreamReader(new FileInputStream(file),"UTF-8");
   br = new BufferedReader(isr);
   String st = br.readLine();
   while (st != null) {
    //脚本变量替换    
    st = st.replaceAll("1%",dbasid);
    st = st.replaceAll("4%",logpath);
    st = st.replaceAll("5%",logpath+"/"+logfile);
    st = st.replaceAll("8%",sqlspacepath);
    st = st.replaceAll("9%",sqlspacefile);    
    st = st.replaceAll("b%",dbaname);
    st = st.replaceAll("c%",dbapwd);
    ps.println(st);
    st = br.readLine();
   }
  } catch (Exception e) {
   e.printStackTrace();
   return "";
  } finally {
   //关闭
   try {
    if (br != null) {
     br.close();
    }
    if (isr != null) {
     isr.close();
    }
    if (ps != null) {
     ps.close();
    }
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
  
  //获得生成的sh文件的文件名
  String filename=shfile.getName();
  //给文件赋权
  this.chmodrun(filename);

  //返回文件名
  return filename;
};

 
 
 
 
    /**
  * 上传到ftp
  * @param url
  * @param port
  * @param username
  * @param password
  * @param path
  * @param filename
  * @param input
  * @return
  * @throws Exception
  */
 public  boolean upload(String url, int port, String username,
   String password, String path, String filename, InputStream input)
   throws Exception {
  boolean success = false;
  FTPClient ftp = new FTPClient();
  try {
   int reply;
   ftp.connect(url, port);// 连接FTP服务器
   // 如果采用默认端口,可以使用ftp.connect(url)的方式直接连接FTP服务器
   ftp.login(username, password);// 登录
   reply = ftp.getReplyCode();
   if (!FTPReply.isPositiveCompletion(reply)) {
    ftp.disconnect();
    // throw new Exception("----------->>>连接ftp服务器失败");
   }
   ftp.changeWorkingDirectory(path);
   
   ftp.storeFile(filename, input); //上传文件

   input.close();
   ftp.logout();
   success = true;
  } catch (Exception e) {
   e.printStackTrace(); 
  } finally {
   if (ftp.isConnected()) {
    try {
     ftp.disconnect();
    } catch (IOException ioe) {
    }
   }
  }
  return success;
 }
 
 
   /**
    * 执行unix shell脚本
    * @param infile String shell脚本名(包含路径)
    * @return int shell脚本的执行结果
    */
   public boolean run(String infile) {   

  //如果配置文件不为true的时候为不需要创建或者删除表空间
    String dbspaceisuse=ApplicationGlobalResource.getInstance().getValueByKey(
  "dbspace.dbspaceisuse");
  if(!dbspaceisuse.equals("true")){
   return true;
  }
   
  
    infile=shfilepath+infile;
    System.out.println("文件全路径:"+infile);
     int retCode = 0;
     try {
       Runtime rtime = Runtime.getRuntime();
       Process child = rtime.exec("sh " +infile);

       retCode=child.waitFor();
       System.out.println("end exec. ret="+retCode);
     }
     catch (Exception e) {
       System.out.println("exec failed");
       e.printStackTrace();
       return false;
     }
     return true;
   }
  
  
  
   /**
    * 执行unix 赋权脚本
    * @param infile String shell脚本名(包含路径)
    * @return int shell脚本的执行结果
    */
   public int chmodrun(String infile) {   

  //如果配置文件不为true的时候为不需要创建或者删除表空间
    String dbspaceisuse=ApplicationGlobalResource.getInstance().getValueByKey(
  "dbspace.dbspaceisuse");
  if(!dbspaceisuse.equals("true")){
   return 1;
  }
   
    infile=spaceshfilepath+infile;
    System.out.println("要修改权限的文件全路径:"+infile);
     int retCode = 0;
     try {
       Runtime rtime = Runtime.getRuntime();
       Process child = rtime.exec("chmod 777 " +infile);

       retCode=child.waitFor();
       System.out.println("chmod 777="+retCode);
     }
     catch (Exception e) {
       System.out.println("chmod 777 failed");
       e.printStackTrace();
     }
     return retCode;
   }
  
   /**
    * 根据日志判断数据库脚本是否执行成功(执行前先创建SHELL脚本,注意UTF-8格式)
    * @param logfile String 日志路径,shfile执行查询sh脚本 0--创建成功,1--创建失败
    */
 
   public  int sqlrun(String logfile, String shfile) { 
    int i=0;
   //如果配置文件不为true的时候为不需要创建或者删除表空间
     String dbspaceisuse=ApplicationGlobalResource.getInstance().getValueByKey("dbspace.dbspaceisuse");
   if(!dbspaceisuse.equals("true")){
    return i;
   }
            String shFilePath=this.shfilepath+shfile;
      try {
       Process p = null;
       InputStream fis = null;
       InputStreamReader isr = null;
       BufferedReader br = null;
       String cmd="sh "+shFilePath;
       System.out.println("cmd:"+cmd);
       p = Runtime.getRuntime().exec(cmd);
       fis = p.getInputStream();
       isr = new InputStreamReader(fis);
       br = new BufferedReader(isr);

       String line = "";      
       while ( (line = br.readLine()) != null)
       {
        System.out.println("line的值"+line);
         if(line.equals("0"))
         {
        System.out.println("删除任务开始");
           Runtime.getRuntime().exec("rm -f "+logfile);
           System.out.println("删除任务结束");         
         } else{
          i=1;
         }      
       }
      }               
      catch (Exception e) {
        System.out.println("exec failed");
        e.printStackTrace(); 
        i=1;
      } 
      return i;
    }  

   
  

   /**
    * 统一对外调用创建接口
    * @param appid
    * @param spacesize 空间大小
    * @param sqlfile 执行的SQL脚本路径
    * @return
    */
  public boolean createdbSpace(String appindex,String appid,String spacesize,String sqlfile ){
   //自增长序列
   Long serverindex = (Long) super.getPrimaryKeyGenerator().getPrimarykey("ucm_server");
   //空间名称
   String spacename="zxin_dbfile_"+serverindex;
   //创建的用户名
   String createuser="zxdbm_app_"+serverindex;
   //创建的密码
   String createpwd="zxin_app_"+String.valueOf((int)(Math.random()*1000)); 
   //生成的执行文件日志
   String logfile="zxin_createdblog_"+serverindex;
   //存放到数据库中的数据库脚本执行日志
   String logfilepath=ApplicationGlobalResource.getInstance().getValueByKey("dbspace.logpath")+logfile;

  String sqlspacefile=this.createdbSpaceSql(spacename, spacesize, createuser, createpwd);//创建表空间需要的sql文件
  System.out.println("创建表空间脚本文件名:"+sqlspacefile);
  if(sqlspacefile.length() ==0){
   return false;
  }
  //此处要判断执行是否成功    sqlfile为用户上传上来的数据库脚本文件
  String infile=this.createInstallSh(createuser, createpwd, sqlfile, sqlspacefile,logfile);//创建执行表空间创建、数据库脚本执行的sh文件
     System.out.println("sh脚本文件名:"+infile);
  if(infile.length() ==0){
   return false;
  }
   
  //执行sh脚本创建表空间和SQL脚本
  boolean boo=this.run(infile); 
  if (boo==false){
   return false;
  }
  
  //创建有关日志的shell脚本,
  String shfile="";
  shfile=this.createCheckLogSh(logfilepath);
  
  //判断脚本是否执行成功
  int c=this.sqlrun(logfile, shfile);  
  
     try{
      //在数据库ucm_server表中增加记录
      UcmServer us=new UcmServer();
      us.setInipaddress(appid);
      us.setServername(spacename);
      us.setServicekey(spacesize);
      us.setFtpaccount(createuser);
      us.setFtppassword(createpwd);
      us.setSrvtypeshortname(dbainstanceid);     
      us.setOutipaddress(dbIP);
      us.setFtpport(dbport);
      us.setFtppath(dbversion);
      us.setDescription(dbtype);     
      ucmServerDS.insertUcmServer(us);
     
      //当创建失败的时候,记录到应用日志中
      if(c==1){
    //更新应用表中的数据库脚本日志路径
       UcmContentBuf ucb=new UcmContentBuf();
       ucb.setContentindex((Long.valueOf(appindex)));
       ucb.setAppsysurl(logfilepath);
       ucmContentBufDS.updateUcmContentBuf(ucb);
       return false;
      }

     
      return true;
     }catch(Exception ex){
      ex.printStackTrace();
      return false;
     }    
  
   }
  
 
 /**
  * 统一对外调用的删除DBSPACE接口
  * @param appid
  * @param state 0--申请同步前,数据在BUF表中 1--当数据在应用表中
  * @return
  */
   public boolean dropdbSpace(String appindex, String appid,int state){

    try{
    System.out.println("appindex:"+appindex);
    System.out.println("appid:"+appid);
         //根据appid找到空间名,所对应的用户名
        UcmServer us=new UcmServer();
        us.setInipaddress(appid);    
      
        List uslist=ucmServerDS.getUcmServerByCond(us);    
        String spacename=uslist.get(0).getServername();
        String createuser=uslist.get(0).getFtpaccount();
        Long serverindex=uslist.get(0).getServerindex();
       
        us.setServerindex(serverindex);
       
       //生成的执行文件日志
        String logfile="zxin_dropdblog_"+serverindex;      
       //存放到数据库中的数据库脚本执行日志
     String logfilepath=ApplicationGlobalResource.getInstance().getValueByKey("dbspace.logpath")+"/"+logfile;
     
    
     String spacefile=this.dropdbSpaceSql(spacename, createuser);
     System.out.println("删除表空间脚本文件名:"+spacefile);
     if(spacefile.length() ==0){
      return false;
     }
     
     String infile=this.dropInstallSh(spacefile,logfile);
        System.out.println("执行删除sh脚本文件名:"+infile);
     if(infile.length() ==0){
      return false;
     }
     
     this.run(infile);

     //删除数据库信息
     ucmServerDS.removeUcmServer(us);
     
       if(state==1){        
          //更新应用表中的数据库脚本日志路径
          UcmContent uc=new UcmContent();
          uc.setContentindex((Long.valueOf(appindex)));
         uc.setAppsysurl(logfilepath); 
         ucmContentDS.updateUcmContent(uc);
       }else{
    //更新BUFFER应用表中的数据库脚本日志路径
       UcmContentBuf ucb=new UcmContentBuf();
       ucb.setContentindex((Long.valueOf(appindex)));
       ucb.setAppsysurl(logfilepath);
       ucmContentBufDS.updateUcmContentBuf(ucb);
       }
       return true; 
    }catch(Exception e){
     e.printStackTrace();
     return false;
    }
 
   }


 public void setUcmServerDS(IUcmServerDS ucmServerDS) {
  this.ucmServerDS = ucmServerDS;
 }

 


 public void setUcmContentBufDS(IUcmContentBufDS ucmContentBufDS) {
  this.ucmContentBufDS = ucmContentBufDS;
 }

 


 public void setUcmContentDS(IUcmContentDS ucmContentDS) {
  this.ucmContentDS = ucmContentDS;
 }


}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

        

   

  

        

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
如何在 RHEL 9 上配置 DHCP 服务器如何在 RHEL 9 上配置 DHCP 服务器Jun 08, 2023 pm 07:02 PM

DHCP是“动态主机配置协议DynamicHostConfigurationProtocol”的首字母缩写词,它是一种网络协议,可自动为计算机网络中的客户端系统分配IP地址。它从DHCP池或在其配置中指定的IP地址范围分配客户端。虽然你可以手动为客户端系统分配静态IP,但DHCP服务器简化了这一过程,并为网络上的客户端系统动态分配IP地址。在本文中,我们将演示如何在RHEL9/RockyLinux9上安装和配置DHCP服务器。先决条件预装RHEL9或RockyLinux9具有sudo管理权限的普

在容器中怎么使用nginx搭建上传下载的文件服务器在容器中怎么使用nginx搭建上传下载的文件服务器May 15, 2023 pm 11:49 PM

一、安装nginx容器为了让nginx支持文件上传,需要下载并运行带有nginx-upload-module模块的容器:sudopodmanpulldocker.io/dimka2014/nginx-upload-with-progress-modules:latestsudopodman-d--namenginx-p83:80docker.io/dimka2014/nginx-upload-with-progress-modules该容器同时带有nginx-upload-module模块和ng

vue3项目打包发布到服务器后访问页面显示空白怎么解决vue3项目打包发布到服务器后访问页面显示空白怎么解决May 17, 2023 am 08:19 AM

vue3项目打包发布到服务器后访问页面显示空白1、处理vue.config.js文件中的publicPath处理如下:const{defineConfig}=require('@vue/cli-service')module.exports=defineConfig({publicPath:process.env.NODE_ENV==='production'?'./':'/&

服务器怎么使用Nginx部署Springboot项目服务器怎么使用Nginx部署Springboot项目May 14, 2023 pm 01:55 PM

1,将java项目打成jar包这里我用到的是maven工具这里有两个项目,打包完成后一个为demo.jar,另一个为jst.jar2.准备工具1.服务器2.域名(注:经过备案)3.xshell用于连接服务器4.winscp(注:视图工具,用于传输jar)3.将jar包传入服务器直接拖动即可3.使用xshell运行jar包注:(服务器的java环境以及maven环境,各位请自行配置,这里不做描述。)cd到jar包路径下执行:nohupjava-jardemo.jar>temp.txt&

python中怎么使用TCP实现对话客户端和服务器python中怎么使用TCP实现对话客户端和服务器May 17, 2023 pm 03:40 PM

TCP客户端一个使用TCP协议实现可连续对话的客户端示例代码:importsocket#客户端配置HOST='localhost'PORT=12345#创建TCP套接字并连接服务器client_socket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)client_socket.connect((HOST,PORT))whileTrue:#获取用户输入message=input("请输入要发送的消息:&

Linux怎么在两个服务器直接传文件Linux怎么在两个服务器直接传文件May 14, 2023 am 09:46 AM

scp是securecopy的简写,是linux系统下基于ssh登陆进行安全的远程文件拷贝命令。scp是加密的,rcp是不加密的,scp是rcp的加强版。因为scp传输是加密的,可能会稍微影响一下速度。另外,scp还非常不占资源,不会提高多少系统负荷,在这一点上,rsync就远远不及它了。虽然rsync比scp会快一点,但当小文件众多的情况下,rsync会导致硬盘I/O非常高,而scp基本不影响系统正常使用。场景:假设我现在有两台服务器(这里的公网ip和内网ip相互传都可以,当然用内网ip相互传

如何使用psutil模块获取服务器的CPU、内存和磁盘使用率?如何使用psutil模块获取服务器的CPU、内存和磁盘使用率?May 07, 2023 pm 10:28 PM

psutil是一个跨平台的Python库,它允许你获取有关系统进程和系统资源使用情况的信息。它支持Windows、Linux、OSX、FreeBSD、OpenBSD和NetBSD等操作系统,并提供了一些非常有用的功能,如:获取系统CPU使用率、内存使用率、磁盘使用率等信息。获取进程列表、进程状态、进程CPU使用率、进程内存使用率、进程IO信息等。杀死进程、发送信号给进程、挂起进程、恢复进程等操作。使用psutil,可以很方便地监控系统的运行状况,诊断问题和优化性能。以下是一个简单的示例,演示如何

怎么在同一台服务器上安装多个MySQL怎么在同一台服务器上安装多个MySQLMay 29, 2023 pm 12:10 PM

一、安装前的准备工作在进行MySQL多实例的安装前,需要进行以下准备工作:准备多个MySQL的安装包,可以从MySQL官网下载适合自己环境的版本进行下载:https://dev.mysql.com/downloads/准备多个MySQL数据目录,可以通过创建不同的目录来支持不同的MySQL实例,例如:/data/mysql1、/data/mysql2等。针对每个MySQL实例,配置一个独立的MySQL用户,该用户拥有对应的MySQL安装路径和数据目录的权限。二、基于二进制包安装多个MySQL实例

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

MinGW - 适用于 Windows 的极简 GNU

MinGW - 适用于 Windows 的极简 GNU

这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

将Eclipse与SAP NetWeaver应用服务器集成。

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

mPDF

mPDF

mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),