-1
private void jMenuItem16ActionPerformed(java.awt.event.ActionEvent evt)  
{                                            

    int r = JOptionPane.showConfirmDialog(null, "Backup ??" , "Backup" , JOptionPane.YES_NO_OPTION);
    if(r==0){
        String filename = BackupNamer.getname();

        try{

            Process rt = Runtime.getRuntime().exec("cmd.exe /C path=C:\\Program Files\\MySQL\\MySQL Server 5.6\\bin;mysqldump -uroot --password=12345 librarysystem>D:\\"+filename+"");


         int pr = rt.waitFor();
         if(pr==0){

             JOptionPane.showMessageDialog(null, "backup created");
         }
         else if(pr==1){

             JOptionPane.showMessageDialog(null, "error");
         }



        }catch(Exception e){

            System.out.println(e);
        }


    }

}

通过这段代码,我想创建我的数据库的备份。但它只在给定路径中创建一个空文件。

4

1 回答 1

0

您的主要问题是您对Runtime.getRuntime().exec(): 它要求程序和所有参数的单独字符串。例如:

Process rt = Runtime.getRuntime().exec("cmd.exe", "/C", "path=C:\\Program Files\\MySQL\\MySQL Server 5.6\\bin;mysqldump", "-uroot", "--password=12345", "librarysystem>D:\\"+filename);
于 2013-06-06T04:22:08.247 回答