论坛首页 入门技术论坛

程序中调用批处理执行Mysql数据库导入导出

浏览 3259 次
该帖已经被评为新手帖
作者 正文
   发表时间:2007-09-03  

     /**
     * @param cmdStr
     * @return
     */
    public static void exec(String cmdStr)throws IOException {
     //�����ʽ��ִ�е�exe Ŀ¼           ��"cmd.exe","   dir"
//        String cmd = "cmd /c start C:/WSCA-ENU-06-12/setpassword.bat";
         String cmd="cmd  /c  start "+cmdStr;
            
            Process ps = Runtime.getRuntime().exec(cmd);
            System.out.print(loadStream(ps.getInputStream()));
            System.err.print(loadStream(ps.getErrorStream()));  
           
    }

------------------------------------------------------------------------------------------------------

import.cmd

set path=d:/axonsams.sql
set path="C:\Program Files\MySQL\MySQL Server 5.0\bin"

@ECHO OFF
CLS

ECHO.
ECHO.
ECHO.
ECHO  进入Mysql目录....
ECHO
pause
ECHO  数据库正在执行中....
mysql --host=localhost --user=root --password=liming -D mysql <%sql%
ECHO.
ECHO 数据库执行完毕
ECHO.
pause
exit

------------------------------------------------------------------------------------------------------

export.bat

set path="C:\Program Files\MySQL\MySQL Server 5.0\bin"
@ECHO OFF
CLS

ECHO.
ECHO.
ECHO.

ECHO  进入Mysql目录....
ECHO.
ECHO.
ECHO  数据库正在保存中....
mysqldump --host=localhost --user=root --password=liming axonsams>d:\axonsams%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%.sql
ECHO.
ECHO.
ECHO   数据库保存路径为ID:\axonsams%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%.sql
ECHO.
ECHO.


exit

 

 

论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics