title: export and import database mysql from java swing
body: <p>I want to export the data base from my swing app tp make a back up
  I was googling about that and the only way worked with me is like that:</p>
  <pre><code>FileWriter fw = null;                   
  
  String path=&quot;C:/Users/mypc/Desktop/tesst/back.sql&quot;;
  String dumpCommand =&quot;mysqldump -u root --password= gestiondestock &gt; &quot;+path;
  // Runtime.getRuntime().exec(&quot;mysqldump -u root --password= gestiondestock &gt; &quot;+path);
  File data = new File(path);
  
  try{
      fw = new FileWriter(data);
      fw.close();
  }catch(IOException ex){
      ex.printStackTrace();
  }
  
  Runtime rt = Runtime.getRuntime();
  
  try {
      Process proc = rt.exec(dumpCommand);
      InputStream in = proc.getInputStream();
      InputStreamReader read = new InputStreamReader(in,&quot;latin1&quot;);
      BufferedReader br = new BufferedReader(read);
      BufferedWriter bw = new BufferedWriter(new FileWriter(data,true));
      String line=null;
      StringBuffer buffer = new StringBuffer();
      
      while ((line=br.readLine())!=null){
          buffer.append(line+&quot;\n&quot;);
      }
      String toWrite = buffer.toString();
      bw.write(toWrite);
      bw.close();
      br.close();
  } catch (IOException e) {
      e.printStackTrace();
  }
  </code></pre>
  <p>but I get only the date base information not the creat table and insert into ....</p>
  <p>i only get this informations:</p>
  <h2>-- MySQL dump 10.10</h2>
  <p>-- Host: localhost    Database: gestiondestock</p>
  <hr />
  <p>-- Server version   5.1.36-community-log</p>
  <pre><code>/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
  /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
  /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
  /*!40101 SET NAMES utf8 */;
  /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
  /*!40103 SET TIME_ZONE='+00:00' */;
  /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
  /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS,    FOREIGN_KEY_CHECKS=0 */;
    /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
     /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
  </code></pre>
  <p>How to fix that and get all the information on the sql file ??, when i try to export on phpmyadmin i get all the information</p>
  <p>the dumpCommand work fine manually from cmd box</p>
  <p>and the best way to import it !!</p>
  <hr />
  <h3>Solution</h3>
  <p>I can't do redirection without running a shell, which I'am not doing above.
  so i have to do this :</p>
  <pre><code> String path=&quot;C:/Users/mypc/Desktop/tesst/back.sql&quot;;
   String dumpCommand = &quot;mysqldump -u root gestiondestock --result-file=&quot;+path;
  </code></pre>
  <p>--result-file=&quot;+path</p>