簡體   English   中英

當我通過網絡致電exec並持續片刻時,它失敗了

[英]When I call exec over network and it last for a few moments, it fails

我有一個用Java和MySQL開發的應用程序。 我通過局域網使用它,並將該應用程序托管在裝有Windows 7 Professional x64的PC上。 該PC用作服務器,不得用於任何其他目的。 我已經共享了應用程序類文件公共駐留的文件夾,其他PC可以使用以下批處理腳本連接到該應用程序:

net use v: \\192.168.0.44\MyAppName
v:
start "" /b javaw -cp .;v:\bin;v:\lib\swt.jar;v:\lib\mysql-connector-java-5.0.8-bin.jar;v:\lib\jdatepicker-1.3.2.jar;v:\lib\commons-io-2.4.jar;v:\lib\jfreechart-1.0.17.jar;v:\lib\jcommon-1.0.21.jar;v:\lib\forms-1.3.0.jar;v:\lib\activation-1.1.jar;v:\lib\commons-email-1.3.2.jar;v:\lib\mail.jar main.Main

所有PC都使用JAVA 7,並且都運行Windows 7、8和Mac(均為64位)。 網絡電纜很大。

該應用程序的所有部分都可以正常工作,只有備份才有問題。 我為此使用了以下Java代碼:

public static boolean getDatabaseBackUp() {
    boolean isSucess = false;
    File dbBackUpFile = new File("db.sql");

    File mysqlDir = new File("\\\\192.168.0.44\\xampp\\mysql");
    File mysqlBinDir = new File(mysqlDir, "bin");
    File mysqlumpFile = new File(mysqlBinDir, "mysqldump.exe");
    String dbUser = "myUserName";
    String dbPass = "myPassword";
    String dbName = "myDbName";
    String executeCmd = "";
    executeCmd = mysqlumpFile + " " + dbName + " -u " + dbUser
            + " --password=" + dbPass + " " + " -r \""
            + dbBackUpFile.getAbsolutePath() + "\"";
    System.out.println(executeCmd);
    try {
        Process runtimeProcess = Runtime.getRuntime().exec(executeCmd);
        int processComplete = runtimeProcess.waitFor();
        if (processComplete == 0) {
            System.out.println("Process is completed");
            isSucess = true;
        } else {
            System.out.println("Process is NOT completed");
            isSucess = false;
        }
    } catch (Exception e) {
        e.printStackTrace();
        isSucess = false;
    }
    return isSucess;
} // getDatabaseBackUp ()

上面的代碼過去在網絡 很小的情況下 在網絡上的所有PC上都能正常工作,包括服務器,我的意思是大約3 MB,但現在已經增長到335 MB 僅當您在服務器PC上打開應用程序,通過網絡從任何其他PC 打開該應用程序時,備份才起作用getDatabaseBackUp()返回false

如果我使用-debug -verbose運行,則輸出為:

\\192.168.0.44\xampp\mysql\bin\mysqldump.exe myApplication -u myUserName --password=myPassword  -r "\\192.168.0.44\myApplication\assets\db_backups\2014_06_10_16_28_13.sql"
[Loaded java.lang.ProcessBuilder from C:\Program Files\Java\jre7\lib\rt.jar]
[Loaded java.lang.Process from C:\Program Files\Java\jre7\lib\rt.jar]
[Loaded java.lang.ProcessImpl from C:\Program Files\Java\jre7\lib\rt.jar]
[Loaded java.lang.ProcessImpl$2 from C:\Program Files\Java\jre7\lib\rt.jar]
Process is NOT completed    

如果我在服務器上運行mysqldump ... --verobse ...mysqldump ... --verobse ...得到:

C:\Users\myPcUserName>\\192.168.0.44\xampp\mysql\bin\mysqldump.exe myApplicationName -u myUserName --password=myPassword  --verbose  -r "\\192.168.0.44\myApplicationName\assets\db_backups\2014_06_11_09_59_56.sql

-- Connecting to localhost...
-- Retrieving table structure for table batch_fault_count...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table batch_insert_time_check...
-- It's a view, create dummy table for view
-- Retrieving table structure for table batch_status_logs...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table batch_types...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table batch_username_for_pq_check...
-- It's a view, create dummy table for view
-- Retrieving table structure for table batches...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table batches_price_list...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table dblock...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table digitally_verified_file_count...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table dvds...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table dvds_batches...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table expense_types...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table expenses...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table files...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table keys_values...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table mailing_list...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table qc_dblock...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table scanners_dirs...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table settings...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table user_check_ins...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table user_groups...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table users...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving table structure for table users_salary...
-- Sending SELECT query...
-- Retrieving rows...
-- Retrieving view structure for table batch_fault_count...
-- It's base table, skipped
-- Retrieving view structure for table batch_insert_time_check...
-- Retrieving view structure for table batch_status_logs...
-- It's base table, skipped
-- Retrieving view structure for table batch_types...
-- It's base table, skipped
-- Retrieving view structure for table batch_username_for_pq_check...
-- Retrieving view structure for table batches...
-- It's base table, skipped
-- Retrieving view structure for table batches_price_list...
-- It's base table, skipped
-- Retrieving view structure for table dblock...
-- It's base table, skipped
-- Retrieving view structure for table digitally_verified_file_count...
-- It's base table, skipped
-- Retrieving view structure for table dvds...
-- It's base table, skipped
-- Retrieving view structure for table dvds_batches...
-- It's base table, skipped
-- Retrieving view structure for table expense_types...
-- It's base table, skipped
-- Retrieving view structure for table expenses...
-- It's base table, skipped
-- Retrieving view structure for table files...
-- It's base table, skipped
-- Retrieving view structure for table keys_values...
-- It's base table, skipped
-- Retrieving view structure for table mailing_list...
-- It's base table, skipped
-- Retrieving view structure for table qc_dblock...
-- It's base table, skipped
-- Retrieving view structure for table scanners_dirs...
-- It's base table, skipped
-- Retrieving view structure for table settings...
-- It's base table, skipped
-- Retrieving view structure for table user_check_ins...
-- It's base table, skipped
-- Retrieving view structure for table user_groups...
-- It's base table, skipped
-- Retrieving view structure for table users...
-- It's base table, skipped
-- Retrieving view structure for table users_salary...
-- It's base table, skipped
-- Disconnecting from localhost...

C:\Users\myPcUserName>

但是,如果我在其他PC上運行mysqldump ... --verobse ...mysqldump ... --verobse ...得到:

C:\Users\myPcUserName>\\192.168.0.44\xampp\mysql\bin\mysqldump.exe myApplicationName -u myUserName --password=myPassword  --verbose  -r "\\192.168.0.44\myApplicationName\assets\db_backups\2014_06_11_09_59_56.sql
-- Connecting to localhost...
mysqldump: Got error: 1049: Unknown database 'myApplicationName' when selecting the database

誰能告訴我問題是什么,我怎么可能解決它?

問題出在主機上。 我沒有在用於生成cmd命令的Java代碼中指定主機。 我需要在cmd命令中使用-h 192.168.0.44 ,因此Java代碼段應如下所示:

File dbBackUpFile = new File("db.sql");

File mysqlDir = new File("\\\\192.168.0.44\\xampp\\mysql");
File mysqlBinDir = new File(mysqlDir, "bin");
File mysqlumpFile = new File(mysqlBinDir, "mysqldump.exe");
String dbUser = "myUserName";
String dbPass = "myPassword";
String dbName = "myDbName";
String dbIp = "192.168.0.44";
    String executeCmd = "";
    executeCmd = mysqlumpFile + " " + dbName + " -u " + dbUser + " -h " + dbIp
            + " --password=" + dbPass + " " + "  -r \""
            + dbBackUpFile.getAbsolutePath() + "\"";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM