java调用mysql命令 导入导出数据库
package com.db.tools;/** * 下面的代码,本人在实际的工程中使用都OK, * 如果由bug,请发信xf.zhouwenjun@163.com 谢谢! */public class SqlControl {// 备份数据库public static void backup(String dbName, String filePath) {try {@SuppressWarnings("unused")Process process = Runtime.getRuntime().exec("cmd /c mysqldump -uroot -psa " + dbName + " > "+ filePath + "/" + new java.util.Date().getTime()+ ".sql");} catch (Exception e) {// TODO Auto-generated catch blockSystem.out.println("备份数据库");e.printStackTrace();}}@SuppressWarnings("unused")// 恢复数据库public static void load(String dbName, String filePath) {try {@SuppressWarnings("unused")Process process = Runtime.getRuntime().exec("cmd /c mysql -uroot -psa " + dbName + " < " + filePath);} catch (Exception e) {// TODO Auto-generated catch blockSystem.out.println("恢复数据库");e.printStackTrace();}}public static void main(String[] args) {try {// backup("mysql2009","d:/");load("test", "d:/1259138711453.sql");System.out.println("ok");} catch (Exception e) {// TODO: handle exceptione.getMessage();}}}1 楼 wander312 2010-05-21 为什么我本地运行你的代码一点反应都没有?