日期:2014-05-16 浏览次数:20915 次
public static String importTableData (String tableName) {
long startTime = System.currentTimeMillis();
StringBuilder sb = new StringBuilder();
Runtime rt = Runtime.getRuntime();
String com = "cmd.exe /c \"E:/Program Files/mysql-5.5.8-win32/bin/mysqlimport\" -u username -ppassword dbName c:/"
+ tableName + ".txt --delete -L --fields-terminated-by=,";
try {
Process p = rt.exec(com);
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while((line = br.readLine()) != null) {
sb.append(line);
}
br = new BufferedReader(new InputStreamReader(p.getErrorStream()));
line = null;
while((line = br.readLine()) != null) {
sb.append(line);
}
if (p != null)
p.destroy();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long endTime = System.currentTimeMillis();
System.out.println("load data to <" + tableName + "> use time : " + (endTime-startTime));
return sb.toString();
}