java 启动、关闭Mysql服务(单例)

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 start(){
try {
logger.info("启动mysql服务...");
// String path = new StringUtil().getWebRoot()+"bat/startMysql.bat";
// logger.info(path);
Runtime.getRuntime().exec("cmd /c start net start mysql");
logger.info("启动mysql服务成功...");
} catch (IOException e) {
logger.info("启动mysql服务失败...");
e.printStackTrace();
}
}

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();
}
}

你可能感兴趣的:(java,C++,c,mysql,C#)