使用Java代碼關閉mysql服務器的方法
Java代碼如下:
package com.jy.pub;
import java.io.IOException;
import com.jy.base.BaseAction;
import com.jy.util.StringUtil;
public class Startmysql extends BaseAction{
private static Startmysql instance =null ;
private Startmysql(){
}
public static Startmysql getInstance(){
if(instance == null){
logger.info("創建instance...");
instance = new Startmysql();
}
return instance ;
}
public void stop(){
try {
logger.info("關閉mysql服務...");
Runtime.getRuntime().exec("cmd /c start net stop mysql");
logger.info("關閉mysql服務成功...");
} catch (IOException e) {
logger.info("關閉mysql服務失敗...");
e.printStackTrace();
}
}
public void backup(){
try {
logger.info("備份數據庫...");
String path = new StringUtil().getWebRoot()+"bat/backup.bat";
Runtime.getRuntime().exec("cmd /c "+path);
logger.info("備份數據庫成功...");
} catch (IOException e) {
logger.info("備份數據庫失敗...");
e.printStackTrace();
}
}
public static void main(String args[]) throws IOException{
Startmysql.getInstance().start();
//Startmysql.getInstance().stop();
}
}