2014-04-09 76 views

回答

0

一個方法是讓mysqldump二進制(從mysql安裝文件)在您的項目目錄,並調用它像:

StringBuilder sb = new StringBuilder("cmd /c mysqldump -h").append(HOSTNAME).append(" -u"); 
sb.append(UNAME).append(" -p").append(PASSWD).append(" ").append(DB_NAME); 
for (String s : tableList) { 
    sb.append(" ").append(s); 
} 
sb.append(" > backup.sql"); 
try { 
    File file = new File("etc/"); 
    Process pr = Runtime.getRuntime().exec(sb.toString(), null, file); 
    pr.waitFor(); 
} catch (IOException | InterruptedException ex) { 
}