91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

數據庫自動備份與手動備份功能的實現

發布時間:2020-07-15 09:31:26 來源:網絡 閱讀:833 作者:NotRepent 欄目:數據庫

前端代碼:

function createBackUp(){

var path=$("#path").val();

$.post("dataBack",{

'path' : path

}, function(data) {

if(data==1){

layer.msg("備份成功!",{time: 2000});

}else{

layer.msg("備份失敗,該路徑不存在!",{time: 2000});

}

}, "text");

}

后端實現:

package com.cloudshield.toolbox4.accountmanage.controller;


import java.io.File;

import java.io.IOException;

import java.io.InputStream;

import java.net.UnknownHostException;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.text.SimpleDateFormat;

import java.util.Properties;

import java.util.Timer;

import java.util.TimerTask;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

import org.springframework.context.annotation.Scope;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

import org.springframework.web.bind.annotation.ResponseBody;

import com.cloudshield.toolbox4.utils.DateUtils;

/**

 * 

 * @XXX

 * @date 2016-10-28 17:24

 *

 */

@Controller

@RequestMapping("/")

@Scope("prototype")

public class DataBackpController {

private static final int BACKUP_SUCCESS=1;/**表示備份成功*/

private static final int BACKUP_ERROR=0;/**表示備份失敗*/

/**手動去備份*/

@ResponseBody

@RequestMapping(value="/dataBack",method = RequestMethod.POST)

public Integer dataBack(HttpServletRequest request,HttpSession session,String time){

Connection conn = null;

try{ /**讀取備份路徑*/

String path = request.getParameter("path");

/**讀取配置文件*/

InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("conn.properties");   

        Properties p = new Properties();

        try {   

        p.load(inputStream);   

        } catch (IOException e1) {   

        e1.printStackTrace();  

       

        /**獲取用戶名密碼以及路徑*/

        String driverName = p.getProperty("c3p0.driverClass");

        String userName=p.getProperty("c3p0.user");

        String passWord=p.getProperty("c3p0.password");

        String url = p.getProperty("c3p0.jdbcUrl");

        Class.forName(driverName).newInstance();

           conn= DriverManager.getConnection(url,userName,passWord);

           backData(path,getDbName(), conn,time);

           return BACKUP_SUCCESS;


}catch(Exception e){

e.printStackTrace();

          

}finally{

try{conn.close();}catch(Exception e){}

}

return BACKUP_ERROR;

}

/**時間設置自動備份*/

@ResponseBody

@RequestMapping(value="/setAutoBackUp",method = RequestMethod.POST)

public Integer setAutoBackUp(HttpServletRequest request,HttpSession session){

try{

Timer timer = new Timer();

final String setupstime = request.getParameter("time");

final String path = request.getParameter("path");

TimerTask task =new TimerTask(){

public void run(){

Connection conn = null;

/**讀取配置文件*/

InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("conn.properties");   

Properties p = new Properties();

try {   

p.load(inputStream);  

/**獲取用戶名密碼以及路徑*/

String driverName = p.getProperty("c3p0.driverClass");

String userName=p.getProperty("c3p0.user");

String passWord=p.getProperty("c3p0.password");

String url = p.getProperty("c3p0.jdbcUrl");

Class.forName(driverName).newInstance();

conn= DriverManager.getConnection(url,userName,passWord);

backData(path,getDbName(),conn,setupstime);

} catch (Exception e1) {   

e1.printStackTrace();  

}finally{

try{conn.close();}catch(Exception e){}

}

}

             

};

if(setupstime!=null&&setupstime.equals("oneday")){

timer.scheduleAtFixedRate(task,DateUtils.getOneday(),DateUtils.getOneday());

}

if(setupstime!=null&&setupstime.equals("week")){

timer.scheduleAtFixedRate(task,DateUtils.getWeek(),DateUtils.getWeek());

}

if(setupstime!=null&&setupstime.equals("halfamonth")){

timer.scheduleAtFixedRate(task,DateUtils.getHalfamonth(),DateUtils.getHalfamonth());

}

if(setupstime!=null&&setupstime.equals("onemonth")){

timer.scheduleAtFixedRate(task,DateUtils.getMonth(),DateUtils.getMonth());

}

if(setupstime!=null&&setupstime.equals("halfayear")){

timer.scheduleAtFixedRate(task,DateUtils.getHalfayear(),DateUtils.getHalfayear());

}

if(setupstime!=null&&setupstime.equals("oneyear")){

timer.scheduleAtFixedRate(task,DateUtils.getOneYear(),DateUtils.getOneYear());

}

return BACKUP_SUCCESS; 


}catch(Exception e){

e.printStackTrace();

          

}

return BACKUP_ERROR;

}

/**備份方法*/

public String backData(String path,String db_name,Connection conn,String time) throws Exception{

/**要返回備份名稱*/

String bk_name = "";

        /**與數據庫進行操作*/

PreparedStatement stmt = null;

        String sql = "";

        try{

        File databasePath = new File(path);

        if(!databasePath.exists()){

        databasePath.mkdir();

        databasePath.setWritable(true);

        }

        String file = new SimpleDateFormat("yyyyMMddHHmmss").format(new java.util.Date())+".bak";

            if(time!=null&&time!=""){

            file="zdbf"+file;

        }

            File newFile=new File(path+File.separator+file);

            newFile.createNewFile();

            newFile.setWritable(true);

            sql = "backup database "+db_name+" to disk=N'"+path+File.separator+file+"' with format,name=N'full backup of "+db_name+"'";

            stmt = conn.prepareStatement(sql);

            stmt.executeUpdate();

            bk_name = file; 

        }catch(Exception e){

            e.printStackTrace();

            throw e;

        }

        finally

        {

        try{stmt.close();} catch(Exception e){}

        }

        return bk_name;

    }

/**獲取要備份的數據庫名字*/

public String getDbName(){

/**讀取配置文件*/

InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("other.properties");   

    Properties p = new Properties();

    try {   

    p.load(inputStream);   

    } catch (IOException e1) {   

    e1.printStackTrace();  

   

    String dbname=p.getProperty("dbName");

   

    return dbname;

}

/**這里不指定post或者get方式的話,默認2中方式都可以*/

@RequestMapping(value = "/autoBackupPage", produces="text/html;charset=UTF-8")

public String autoBackupPage(HttpServletRequest request, HttpServletResponse response) throws UnknownHostException, IOException{

return "jsp/accountManage/backupWindow";

}

/**跳轉數據備份的主頁面*/

@RequestMapping(value = "/toBackupPage", produces="text/html;charset=UTF-8")

public String toBackupPage(HttpServletRequest request, HttpServletResponse response) throws UnknownHostException, IOException{

return "jsp/accountManage/backUp";

}

}

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

抚松县| 赤城县| 临武县| 七台河市| 华安县| 永福县| 宁远县| 焦作市| 杭锦后旗| 武安市| 雷州市| 广东省| 偏关县| 洪雅县| 南通市| 陆丰市| 崇文区| 晋城| 新沂市| 内江市| 大荔县| 五河县| 嘉禾县| 茶陵县| 醴陵市| 青阳县| 漳州市| 石家庄市| 曲周县| 鲜城| 渭南市| 长宁县| 登封市| 陈巴尔虎旗| 海原县| 岐山县| 宣恩县| 甘孜| 中牟县| 普洱| 五大连池市|